NSLogger is a lightweight class for iOS versions 3.0 and above. It allows developers to easily log different 'events' over time which are locally stored as a .txt file.
To use NSLogger add both of the following code samples to each view controller you wish to use.
In your .h file add #import "NSLogger.h"
In your .m file add NSLogger *logger = [[NSLogger alloc] init];
logger.degbugger = true;
Events are what are created every time you create a new item in NSLogger. They contain 2 objects, a "title" and "properties"
"title" type: NSString
"properties" type: NSDictionary
Creating an event can be done by calling the following method ¬
[logger log:@"Event Title" properties:[NSDictionary dictionaryWithObjectsAndKeys:@"value", @"key", [NSNumber numberWithBool:true] ,@"installed"];
NOTE title cannot be empty or NULL
To print out the entire log file in the debugger console useNSLog(@"Logger Print: %@" ,[logger logPrint]);
There will be many ways you will choose to utilize the saved data. Sending it as an attachment is the most common so we have added an example for you lazy folk out there
MFMailComposeViewController *emailController = [[MFMailComposeViewController alloc] init]; [emailController setMailComposeDelegate:self]; [emailController setToRecipients:[[NSArray alloc] initWithObjects:@"[email protected]", nil]]; [emailController setSubject:@"Log File"]; [emailController setMessageBody:@"" isHTML:false]; [emailController addAttachmentData:[logger logData] mimeType:@"text/plain" fileName:@"logger.txt"]; [emailController setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; [self presentViewController:emailController animated:true completion:nil];
NOTE the fileName for addAttachmentData can be anything