IOS prints Debug logs.

Source: Internet
Author: User

IOS prints Debug logs.

The following macros are briefly introduced:

1) _ VA_ARGS _ is a macro of a variable parameter. The macro of this variable parameter is added in the new C99 specification, currently, only gcc is supported (not supported by the VC6.0 compiler ). # Is added before the Macro. When the number of variable parameters is 0, # is used to remove ",". Otherwise, compilation errors may occur.
2) _ FILE _ Macro will be replaced with the current source FILE name during pre-compilation.
3) _ LINE _ Macro will be replaced with the current row number during pre-compilation.
4) _ FUNCTION _ macro is replaced with the current FUNCTION name during pre-compilation.

 

1. Redefine the NSLog of the system. __optimize _ is the macro that will be added by default to release.

 

[Plain]View plaincopy
  1. # Ifndef _ OPTIMIZE __
  2. # Define NSLog (...) NSLog (_ VA_ARGS __)
  3. # Else
  4. # Define NSLog (...){}
  5. # Endif

 

 

2. Write # define directly. When the release version is released, comment out # define.

 

# Define IOS_DEBUG

 

[Plain]View plaincopy
  1. # Ifdef IOS_DEBUG
  2. # Define NSLog (...) NSLog (_ VA_ARGS __)
  3. # Endif

 

3.

[Plain]View plaincopy
  1. # Ifdef DEBUG
  2. # Define DLog (format ,...) NSLog (@ "[FILE Name: % s]" "[function name: % s]" "[line number: % d]" format), _ FILE __, _ FUNCTION __, _ LINE __, ##__ VA_ARGS __);
  3. # Else
  4. # Define DLog (...);
  5. # Endif

In this way, you need to modify the configuration of the project so that the DLog macro can be compiled during debug compilation to generate detailed log information. In release mode, no console output is generated.

In comparison, the first one is more convenient.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.