OverflowTestMacAppDelegate.m 2.3 KB

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