Skip to content

T101Limited/NSLogger

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

NSLogger

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.

Setup

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];

Debugging

to enable console debugging simply add this ¬
logger.degbugger = true;

"Events"

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

Print

To print out the entire log file in the debugger console use
NSLog(@"Logger Print: %@" ,[logger logPrint]);

BONUS: Send as Attachement

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