Use SimpleLogger log classification in IOS applications

Source: Internet
Author: User

IOSUsed in applicationsSimpleLogger logClassification is the content to be introduced in this article.IOSInLogsClassify an instance.

See an article in the jarIOSMediumLogsManage the content and share it with your friends. I used Log4j for log classification during java, but now I have been using NSLog for iphone for a while.LogsBut we need some powerfulLogsFunction, suchLogsLevel Control, printing of row numbers and file names, etc. There is an open-source Log4Cocoa.

I have been learning Object-C and iPhone for nearly two months. The NSLog function is used in the first chapter of almost any book about Object-C. This function can output some information to the Console, it is convenient for us to track the running process of the program. However, when I was developing some iPhones, I needed some powerful log functions, such as file names, row numbers, and some Log Level Control. I found it on Google. There is a Log4Cocoa which seems to be intended to be a function of Log4j. However, I do not need to be so powerful at ordinary times, and I do not like to use a cool knife, so I wrote a simple logstore, SimpleLogger.

In fact, this cannot be used as a database. To put it bluntly, the files SimpleLogger. h and SimpleLogger. m are simple enough. I have defined some common macros, such as DEBUG, ENTER, and RETURN. You can view the source code or the example of MyLogger. m to know how to use them. This logstore supports iPhone and MacOSX development, but it is not thread-safe (the iPhone does not have this problem ).

[Usage]

Let's take a look at the following code:

 
 
  1. #import <Foundation/Foundation.h>     
  2. #import "SimpleLogger.h"     
  3.     
  4. int testLogger()     
  5. {     
  6.     ENTER(@"testLogger()");     
  7.     int rst = 10;     
  8.     RETURN(-rst, @"%d", -rst);     
  9. }     
  10.     
  11. int main (int argc, const char * argv[]) {     
  12.     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];     
  13.     [SimpleLogger getLogger];     
  14.          
  15.     //insert code here     
  16.     int i = 10;     
  17.     INFO(@"i is %d", i);     
  18.     i = -100;     
  19.     INFO(@"i is %d", i);            
  20.     testLogger();     
  21.     [pool drain];     
  22.     [[SimpleLogger getLogger]release];     
  23.     return 0;      
  24. }    
  25.  
  26. #import <Foundation/Foundation.h> 
  27. #import "SimpleLogger.h"  
  28.  
  29. int testLogger()  
  30. {  
  31.     ENTER(@"testLogger()");  
  32.     int rst = 10;  
  33.     RETURN(-rst, @"%d", -rst);  
  34. }  
  35.  
  36. int main (int argc, const char * argv[]) {  
  37.     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];  
  38.     [SimpleLogger getLogger];  
  39.       
  40.     //insert code here  
  41.     int i = 10;  
  42.     INFO(@"i is %d", i);  
  43.     i = -100;  
  44.     INFO(@"i is %d", i);         
  45.     testLogger();  
  46.     [pool drain];  
  47.     [[SimpleLogger getLogger]release];  
  48.     return 0;   

Easy to use

1) Add SimpleLogger. h and SimpleLogger. m to your project.

2) Call [[SimpleLogger getLogger] setLogLevelSetting: SOME_LEGEL]; (optional) The default value is SLLE_MAJOR)

3) Call [[SimpleLogger getLogger] release]

4) common methods:

 
 
  1. ENTER (@ "method name ");
  2. INFO (@ "The count of array is % d", [array count]);
  3. DEBUG (@ "The person's name is % @", person. name );
  4. ERROR (@ "Impossible get into this branch ");
  5. RETURN (rst, @ "% d", rst); // rst indicates the returned value.
  6. LOG (SLL_DETAILED, @ "This log is very detailed with value % d", value );
  7. [[SimpleLogger getLogger] setLogLevelSetting: SLLS_MINOR]; // set the Log Level

Download Library: http://wangjun.easymorse.com/wp-content/tools/SimpleLogger.zip

MyLogger.tar: http://dl.iteye.com/topics/download/2898cb63-c4c6-3042-be73-2e173cac2a64

Summary:IOSUsed in applicationsSimpleLogger logThe classification content has been introduced. I hope this article will help you!

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.