GDLogger is a lightweight class logging class for iOS versions 3.0 and above, build for Grado. It allows for quick, strightforward creation, and appending of multiple, formatted log files.
We now support CocoaPod'spod 'GDLogger'
Add #import "GDLogger/GDLogger.h"
In your .m file add GDLogger *logger = [[GDLogger alloc] init];
logger.degbugger = true;
We recently updated GDLogger to support multiple log files. By default there will be only one log file saved locally "[YourApp]-logger.txt". This is created when you log your first event. To create a new log file simply set the filename.
logger.filename = @"my-new-log";
NOTE To revert back to the default log file set logger.filename = nil;
NOTE Do not include the file type when setting logger.filename
Events are what are created every time you create a new item in GDLogger. They contain 2 objects, a "title" and "properties"
title (NSString
properties (NSDictionary)
[logger log:@"Event Title" properties:@{@"key":@"value", @"installed":[NSNumber numberWithBool:true]}];
logger.logPrint
Alternatively, you can get the file content as NSData logger.logData
NOTE this will print out the default log file unless logger.filename
has been set
There is two ways of getting access to the saved files.
You can get the active most recent file by calling
logger.logPrint
Or, you can get an array of all files by calling
[self.logger logFiles:true]
(This will return the all the files with their full directories as NSURL)
[self.logger logFiles:false]
(This will return the all the files with just their respective file names as NSString)
Calling
[self logDestory];
will destory the active log file.
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@gmail.com", 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