SQLiteLoggerAppDelegate.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // SQLiteLoggerAppDelegate.m
  3. // SQLiteLogger
  4. //
  5. // CocoaLumberjack Demos
  6. //
  7. #import "SQLiteLoggerAppDelegate.h"
  8. #import <CocoaLumberjack/CocoaLumberjack.h>
  9. #import "FMDBLogger.h"
  10. // Log levels: off, error, warn, info, verbose
  11. static const DDLogLevel ddLogLevel = DDLogLevelVerbose;
  12. @implementation SQLiteLoggerAppDelegate
  13. @synthesize window;
  14. - (NSString *)applicationFilesDirectory
  15. {
  16. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
  17. NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : NSTemporaryDirectory();
  18. return [basePath stringByAppendingPathComponent:@"SQLiteLogger"];
  19. }
  20. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
  21. {
  22. // [DDLog addLogger:[DDTTYLogger sharedInstance]];
  23. sqliteLogger = [[FMDBLogger alloc] initWithLogDirectory:[self applicationFilesDirectory]];
  24. sqliteLogger.saveThreshold = 500;
  25. sqliteLogger.saveInterval = 60; // 60 seconds
  26. sqliteLogger.maxAge = 60 * 60 * 24 * 7; // 7 days
  27. sqliteLogger.deleteInterval = 60 * 5; // 5 minutes
  28. sqliteLogger.deleteOnEverySave = NO;
  29. [DDLog addLogger:sqliteLogger];
  30. [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(doTest:) userInfo:nil repeats:NO];
  31. }
  32. - (void)doTest:(NSTimer *)aTimer
  33. {
  34. NSDate *start = [NSDate date];
  35. int i;
  36. for (i = 0; i < 1000; i++)
  37. {
  38. DDLogVerbose(@"A log message of average size");
  39. }
  40. [DDLog flushLog];
  41. NSTimeInterval elapsed = [start timeIntervalSinceNow] * -1.0;
  42. NSLog(@"Total time: %.4f", elapsed);
  43. }
  44. @end