OverflowTestMacAppDelegate.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #import "OverflowTestMacAppDelegate.h"
  2. #import <CocoaLumberjack/CocoaLumberjack.h>
  3. #import "SlowLogger.h"
  4. // Debug levels: off, error, warn, info, verbose
  5. static const DDLogLevel ddLogLevel = DDLogLevelVerbose;
  6. @implementation OverflowTestMacAppDelegate
  7. @synthesize window;
  8. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
  9. {
  10. // Since logging can be asynchronous, its possible for rogue threads to flood the logging queue.
  11. // That is, to issue an abundance of log statements faster than the logging thread can keepup.
  12. // Typically such a scenario occurs when log statements are added haphazardly within large loops,
  13. // but may also be possible if relatively slow loggers are being used.
  14. //
  15. // Lumberjack has the ability to cap the queue size at a given number of outstanding log statements.
  16. // If a thread attempts to issue a log statement when the queue is already maxed out,
  17. // the issuing thread will block until the queue size drops below the max again.
  18. //
  19. // This Xcode project demonstrates this feature by using a "Slow Logger".
  20. NSLog(@"How to use this test:");
  21. NSLog(@"1. Set the DEBUG definition to YES in DDLog.m");
  22. NSLog(@"2. Set the LOG_MAX_QUEUE_SIZE definition to 5 in DDLog.m\n\n");
  23. SlowLogger *slowLogger = [[SlowLogger alloc] init];
  24. [DDLog addLogger:slowLogger];
  25. [DDLog addLogger:[DDASLLogger sharedInstance]];
  26. [DDLog addLogger:[DDTTYLogger sharedInstance]];
  27. [NSThread detachNewThreadSelector:@selector(bgThread1) toTarget:self withObject:nil];
  28. [NSThread detachNewThreadSelector:@selector(bgThread2) toTarget:self withObject:nil];
  29. NSLog(@"mainThread");
  30. for (int i = 0; i < 10; i++)
  31. {
  32. DDLogVerbose(@"mainThread: %i", i);
  33. }
  34. [DDLog flushLog];
  35. }
  36. - (void)bgThread1
  37. {
  38. @autoreleasepool {
  39. NSLog(@"bgThread1");
  40. for (int i = 0; i < 10; i++)
  41. {
  42. DDLogVerbose(@"bgThread1 : %i", i);
  43. }
  44. }
  45. }
  46. - (void)bgThread2
  47. {
  48. @autoreleasepool {
  49. NSLog(@"bgThread2");
  50. for (int i = 0; i < 10; i++)
  51. {
  52. DDLogVerbose(@"bgThread2 : %i", i);
  53. }
  54. }
  55. }
  56. @end