Permalink
Browse files

Adding example to demonstrate DispatchQueueLogFormatter

  • Loading branch information...
robbiehanson committed Nov 9, 2011
1 parent f39688d commit 8bf1951d418f2890a53b6d0fe311bfa8c628f925

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,15 @@
+//
+// AppDelegate.h
+// DispatchQueueLogger
+//
+// Created by Robbie Hanson on 11/8/11.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@interface AppDelegate : NSObject <NSApplicationDelegate>
+
+@property (assign) IBOutlet NSWindow *window;
+
+@end
@@ -0,0 +1,91 @@
+#import "AppDelegate.h"
+#import "DDLog.h"
+#import "DDTTYLogger.h"
+#import "DispatchQueueLogFormatter.h"
+
+// Log levels: 0-off, 1-error, 2-warn, 3-info, 4-verbose
+static const int ddLogLevel = LOG_LEVEL_VERBOSE;
+
+
+@implementation AppDelegate
+{
+ dispatch_queue_t downloadingQueue;
+ dispatch_queue_t parsingQueue;
+ dispatch_queue_t processingQueue;
+}
+
+@synthesize window = _window;
+
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
+{
+ if (YES)
+ {
+ // Log statements *AFTER* DispatchQueueLogFormatter
+
+ DispatchQueueLogFormatter *formatter = [[[DispatchQueueLogFormatter alloc] init] autorelease];
+ formatter.queueLength = 17;
+ formatter.rightAlign = NO;
+
+ [formatter setReplacementString:@"main" forQueueLabel:@"com.apple.main-thread"];
+ [formatter setReplacementString:@"global-background" forQueueLabel:@"com.apple.root.background-priority"];
+ [formatter setReplacementString:@"global-low" forQueueLabel:@"com.apple.root.low-priority"];
+ [formatter setReplacementString:@"global-default" forQueueLabel:@"com.apple.root.default-priority"];
+ [formatter setReplacementString:@"global-high" forQueueLabel:@"com.apple.root.high-priority"];
+
+ [formatter setReplacementString:@"downloading" forQueueLabel:@"downloadingQueue"];
+ [formatter setReplacementString:@"parsing" forQueueLabel:@"parsingQueue"];
+ [formatter setReplacementString:@"processing" forQueueLabel:@"processingQueue"];
+
+ [[DDTTYLogger sharedInstance] setLogFormatter:formatter];
+ }
+ else
+ {
+ // Log statements *BEFORE* DispatchQueueLogFormatter
+ }
+
+ [DDLog addLogger:[DDTTYLogger sharedInstance]];
+
+ DDLogVerbose(@"Starting queues");
+
+ downloadingQueue = dispatch_queue_create("downloadingQueue", NULL);
+ parsingQueue = dispatch_queue_create("parsingQueue", NULL);
+ processingQueue = dispatch_queue_create("processingQueue", NULL);
+
+ dispatch_block_t blockA = ^{
+ DDLogVerbose(@"Some log statement");
+ };
+ dispatch_block_t blockB = ^{
+ DDLogVerbose(@"Some log statement");
+ };
+ dispatch_block_t blockC = ^{
+ DDLogVerbose(@"Some log statement");
+ };
+
+ int i, count = 5;
+
+ for (i = 0; i < count; i++)
+ {
+ dispatch_async(downloadingQueue, blockA);
+ dispatch_async(parsingQueue, blockB);
+ dispatch_async(processingQueue, blockC);
+ }
+
+ dispatch_queue_t bgq = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
+ dispatch_queue_t lgq = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
+ dispatch_queue_t dgq = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+ dispatch_queue_t hgq = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
+
+ dispatch_block_t blockD = ^{
+ DDLogVerbose(@"Some log statement");
+ };
+
+ for (i = 0; i < count; i++)
+ {
+ dispatch_async(bgq, blockD);
+ dispatch_async(lgq, blockD);
+ dispatch_async(dgq, blockD);
+ dispatch_async(hgq, blockD);
+ }
+}
+
+@end
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.deusty.oss.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>${MACOSX_DEPLOYMENT_TARGET}</string>
+ <key>NSHumanReadableCopyright</key>
+ <string>Copyright © 2011 __MyCompanyName__. All rights reserved.</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
@@ -0,0 +1,7 @@
+//
+// Prefix header for all source files of the 'DispatchQueueLogger' target in the 'DispatchQueueLogger' project
+//
+
+#ifdef __OBJC__
+ #import <Cocoa/Cocoa.h>
+#endif
@@ -0,0 +1,29 @@
+{\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;}
+{\colortbl;\red255\green255\blue255;}
+\paperw9840\paperh8400
+\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
+
+\f0\b\fs24 \cf0 Engineering:
+\b0 \
+ Some people\
+\
+
+\b Human Interface Design:
+\b0 \
+ Some other people\
+\
+
+\b Testing:
+\b0 \
+ Hopefully not nobody\
+\
+
+\b Documentation:
+\b0 \
+ Whoever\
+\
+
+\b With special thanks to:
+\b0 \
+ Mom\
+}
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
Oops, something went wrong.

0 comments on commit 8bf1951

Please sign in to comment.