Permalink
Browse files

Adding color support to DDTTYLogger (yes, even colors in Xcode debugg…

…ing console)!
  • Loading branch information...
robbiehanson committed May 24, 2012
1 parent ed42d3f commit 2b2a2fb3a1967357692107b8797962c1f3b59fc5
Showing with 6,912 additions and 59 deletions.
  1. +60 −6 Lumberjack/DDTTYLogger.h
  2. +1,160 −53 Lumberjack/DDTTYLogger.m
  3. +359 −0 Xcode/Testing/TestXcodeColors/Desktop/TestXcodeColors.xcodeproj/project.pbxproj
  4. +8 −0 Xcode/Testing/TestXcodeColors/Desktop/TestXcodeColors/AppDelegate.h
  5. +42 −0 Xcode/Testing/TestXcodeColors/Desktop/TestXcodeColors/AppDelegate.m
  6. +34 −0 Xcode/Testing/TestXcodeColors/Desktop/TestXcodeColors/TestXcodeColors-Info.plist
  7. +7 −0 Xcode/Testing/TestXcodeColors/Desktop/TestXcodeColors/TestXcodeColors-Prefix.pch
  8. +29 −0 Xcode/Testing/TestXcodeColors/Desktop/TestXcodeColors/en.lproj/Credits.rtf
  9. +2 −0 Xcode/Testing/TestXcodeColors/Desktop/TestXcodeColors/en.lproj/InfoPlist.strings
  10. +4,587 −0 Xcode/Testing/TestXcodeColors/Desktop/TestXcodeColors/en.lproj/MainMenu.xib
  11. +14 −0 Xcode/Testing/TestXcodeColors/Desktop/TestXcodeColors/main.m
  12. +345 −0 Xcode/Testing/TestXcodeColors/Mobile/TextXcodeColors.xcodeproj/project.pbxproj
  13. +11 −0 Xcode/Testing/TestXcodeColors/Mobile/TextXcodeColors/AppDelegate.h
  14. +52 −0 Xcode/Testing/TestXcodeColors/Mobile/TextXcodeColors/AppDelegate.m
  15. +38 −0 Xcode/Testing/TestXcodeColors/Mobile/TextXcodeColors/TextXcodeColors-Info.plist
  16. +14 −0 Xcode/Testing/TestXcodeColors/Mobile/TextXcodeColors/TextXcodeColors-Prefix.pch
  17. +5 −0 Xcode/Testing/TestXcodeColors/Mobile/TextXcodeColors/ViewController.h
  18. +6 −0 Xcode/Testing/TestXcodeColors/Mobile/TextXcodeColors/ViewController.m
  19. +2 −0 Xcode/Testing/TestXcodeColors/Mobile/TextXcodeColors/en.lproj/InfoPlist.strings
  20. +119 −0 Xcode/Testing/TestXcodeColors/Mobile/TextXcodeColors/en.lproj/ViewController.xib
  21. +18 −0 Xcode/Testing/TestXcodeColors/Mobile/TextXcodeColors/main.m
View
@@ -28,19 +28,73 @@
@interface DDTTYLogger : DDAbstractLogger <DDLogger>
{
- BOOL isaTTY;
-
- NSDateFormatter *dateFormatter;
-
- char *app; // Not null terminated
- char *pid; // Not null terminated
+ NSCalendar *calendar;
+ NSUInteger calendarUnitFlags;
+ NSString *appName;
+ char *app;
size_t appLen;
+
+ NSString *processID;
+ char *pid;
size_t pidLen;
+
+ BOOL colorsEnabled;
+ NSMutableArray *colorProfiles;
}
+ (DDTTYLogger *)sharedInstance;
+/**
+ * Want to use different colors for different log levels?
+ * Enable this property.
+ *
+ * If you run the application via the Terminal (not Xcode),
+ * the logger will map colors to xterm-256color or xterm-color (if available).
+ *
+ * Xcode does NOT natively support colors in the Xcode debugging console.
+ * You'll need to install the XcodeColors plugin to see colors in the Xcode console.
+ * https://github.com/robbiehanson/XcodeColors
+ *
+ * The default value if NO.
+**/
+@property (readwrite, assign) BOOL colorsEnabled;
+
+/**
+ * The default color set (foregroundColor, backgroundColor) is:
+ *
+ * - LOG_FLAG_ERROR = (red, nil)
+ * - LOG_FLAG_WARN = (orange, nil)
+ *
+ * You can customize the colors however you see fit.
+ * There are a few things you may need to be aware of:
+ *
+ * You are passing a flag, NOT a level.
+ *
+ * GOOD : [ttyLogger setForegroundColor:pink backgroundColor:nil forFlag:LOG_FLAG_INFO]; // <- Good :)
+ * BAD : [ttyLogger setForegroundColor:pink backgroundColor:nil forFlag:LOG_LEVEL_INFO]; // <- BAD! :(
+ *
+ * LOG_FLAG_INFO = 0...00100
+ * LOG_LEVEL_INFO = 0...00111 <- Would match LOG_FLAG_INFO and LOG_FLAG_WARN and LOG_FLAG_ERROR
+ *
+ * If you run the application within Xcode, then the XcodeColors plugin is required.
+ *
+ * If you run the application from a shell, then DDTTYLogger will automatically try to map the given color to
+ * the closest available color. (xterm-256color or xterm-color which have 256 and 16 supported colors respectively.)
+**/
+#if TARGET_OS_IPHONE
+- (void)setForegroundColor:(UIColor *)txtColor backgroundColor:(UIColor *)bgColor forFlag:(int)mask;
+#else
+- (void)setForegroundColor:(NSColor *)txtColor backgroundColor:(NSColor *)bgColor forFlag:(int)mask;
+#endif
+
+/**
+ * Allows you to clear color mappings, either per flag or all.
+**/
+- (void)clearColorsForFlag:(int)mask;
+- (void)clearColorsForAllFlags;
+
+
// Inherited from DDAbstractLogger
// - (id <DDLogFormatter>)logFormatter;
Oops, something went wrong.

2 comments on commit 2b2a2fb

@PaulCapestany

This comment has been minimized.

Show comment Hide comment
@PaulCapestany

PaulCapestany May 24, 2012

This is awesome! I had discovered XCodeColors recently and had grafted it on to work with CocoaLumberjack myself, great to see you incorporate it into the main codebase though :)

This is awesome! I had discovered XCodeColors recently and had grafted it on to work with CocoaLumberjack myself, great to see you incorporate it into the main codebase though :)

@vgavrilov

This comment has been minimized.

Show comment Hide comment
@vgavrilov

vgavrilov May 25, 2012

What a great update! :)

What a great update! :)

Please sign in to comment.