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:
- #import <Foundation/Foundation.h>
- #import "SimpleLogger.h"
-
- int testLogger()
- {
- ENTER(@"testLogger()");
- int rst = 10;
- RETURN(-rst, @"%d", -rst);
- }
-
- int main (int argc, const char * argv[]) {
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
- [SimpleLogger getLogger];
-
- //insert code here
- int i = 10;
- INFO(@"i is %d", i);
- i = -100;
- INFO(@"i is %d", i);
- testLogger();
- [pool drain];
- [[SimpleLogger getLogger]release];
- return 0;
- }
-
- #import <Foundation/Foundation.h>
- #import "SimpleLogger.h"
-
- int testLogger()
- {
- ENTER(@"testLogger()");
- int rst = 10;
- RETURN(-rst, @"%d", -rst);
- }
-
- int main (int argc, const char * argv[]) {
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
- [SimpleLogger getLogger];
-
- //insert code here
- int i = 10;
- INFO(@"i is %d", i);
- i = -100;
- INFO(@"i is %d", i);
- testLogger();
- [pool drain];
- [[SimpleLogger getLogger]release];
- 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:
- ENTER (@ "method name ");
- INFO (@ "The count of array is % d", [array count]);
- DEBUG (@ "The person's name is % @", person. name );
- ERROR (@ "Impossible get into this branch ");
- RETURN (rst, @ "% d", rst); // rst indicates the returned value.
- LOG (SLL_DETAILED, @ "This log is very detailed with value % d", value );
- [[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!