Subversion Repositories Mobile Apps.GyroMouse

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pmbaty 1
#import <Foundation/Foundation.h>
2
#if TARGET_OS_IPHONE
3
#import <UIKit/UIColor.h>
4
#else
5
#import <AppKit/NSColor.h>
6
#endif
7
 
8
#import "DDLog.h"
9
 
10
#define LOG_CONTEXT_ALL INT_MAX
11
 
12
/**
13
 * Welcome to Cocoa Lumberjack!
14
 *
15
 * The project page has a wealth of documentation if you have any questions.
16
 * https://github.com/CocoaLumberjack/CocoaLumberjack
17
 *
18
 * If you're new to the project you may wish to read the "Getting Started" wiki.
19
 * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/GettingStarted
20
 *
21
 *
22
 * This class provides a logger for Terminal output or Xcode console output,
23
 * depending on where you are running your code.
24
 *
25
 * As described in the "Getting Started" page,
26
 * the traditional NSLog() function directs it's output to two places:
27
 *
28
 * - Apple System Log (so it shows up in Console.app)
29
 * - StdErr (if stderr is a TTY, so log statements show up in Xcode console)
30
 *
31
 * To duplicate NSLog() functionality you can simply add this logger and an asl logger.
32
 * However, if you instead choose to use file logging (for faster performance),
33
 * you may choose to use only a file logger and a tty logger.
34
**/
35
 
36
@interface DDTTYLogger : DDAbstractLogger <DDLogger>
37
{
38
    NSCalendar *calendar;
39
    NSUInteger calendarUnitFlags;
40
 
41
    NSString *appName;
42
    char *app;
43
    size_t appLen;
44
 
45
    NSString *processID;
46
    char *pid;
47
    size_t pidLen;
48
 
49
    BOOL colorsEnabled;
50
    NSMutableArray *colorProfilesArray;
51
    NSMutableDictionary *colorProfilesDict;
52
}
53
 
54
+ (instancetype)sharedInstance;
55
 
56
/* Inherited from the DDLogger protocol:
57
 *
58
 * Formatters may optionally be added to any logger.
59
 *
60
 * If no formatter is set, the logger simply logs the message as it is given in logMessage,
61
 * or it may use its own built in formatting style.
62
 *
63
 * More information about formatters can be found here:
64
 * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/CustomFormatters
65
 *
66
 * The actual implementation of these methods is inherited from DDAbstractLogger.
67
 
68
- (id <DDLogFormatter>)logFormatter;
69
- (void)setLogFormatter:(id <DDLogFormatter>)formatter;
70
 
71
*/
72
 
73
/**
74
 * Want to use different colors for different log levels?
75
 * Enable this property.
76
 *
77
 * If you run the application via the Terminal (not Xcode),
78
 * the logger will map colors to xterm-256color or xterm-color (if available).
79
 *
80
 * Xcode does NOT natively support colors in the Xcode debugging console.
81
 * You'll need to install the XcodeColors plugin to see colors in the Xcode console.
82
 * https://github.com/robbiehanson/XcodeColors
83
 *
84
 * The default value if NO.
85
**/
86
@property (readwrite, assign) BOOL colorsEnabled;
87
 
88
/**
89
 * The default color set (foregroundColor, backgroundColor) is:
90
 *
91
 * - LOG_FLAG_ERROR = (red, nil)
92
 * - LOG_FLAG_WARN  = (orange, nil)
93
 *
94
 * You can customize the colors however you see fit.
95
 * Please note that you are passing a flag, NOT a level.
96
 *
97
 * GOOD : [ttyLogger setForegroundColor:pink backgroundColor:nil forFlag:LOG_FLAG_INFO];  // <- Good :)
98
 *  BAD : [ttyLogger setForegroundColor:pink backgroundColor:nil forFlag:LOG_LEVEL_INFO]; // <- BAD! :(
99
 *
100
 * LOG_FLAG_INFO  = 0...00100
101
 * LOG_LEVEL_INFO = 0...00111 <- Would match LOG_FLAG_INFO and LOG_FLAG_WARN and LOG_FLAG_ERROR
102
 *
103
 * If you run the application within Xcode, then the XcodeColors plugin is required.
104
 *
105
 * If you run the application from a shell, then DDTTYLogger will automatically map the given color to
106
 * the closest available color. (xterm-256color or xterm-color which have 256 and 16 supported colors respectively.)
107
 *
108
 * This method invokes setForegroundColor:backgroundColor:forFlag:context: and applies it to `LOG_CONTEXT_ALL`.
109
**/
110
#if TARGET_OS_IPHONE
111
- (void)setForegroundColor:(UIColor *)txtColor backgroundColor:(UIColor *)bgColor forFlag:(int)mask;
112
#else
113
- (void)setForegroundColor:(NSColor *)txtColor backgroundColor:(NSColor *)bgColor forFlag:(int)mask;
114
#endif
115
 
116
/**
117
 * Just like setForegroundColor:backgroundColor:flag, but allows you to specify a particular logging context.
118
 *
119
 * A logging context is often used to identify log messages coming from a 3rd party framework,
120
 * although logging context's can be used for many different functions.
121
 *
122
 * Use LOG_CONTEXT_ALL to set the deafult color for all contexts that have no specific color set defined.
123
 *
124
 * Logging context's are explained in further detail here:
125
 * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/CustomContext
126
**/
127
#if TARGET_OS_IPHONE
128
- (void)setForegroundColor:(UIColor *)txtColor backgroundColor:(UIColor *)bgColor forFlag:(int)mask context:(int)ctxt;
129
#else
130
- (void)setForegroundColor:(NSColor *)txtColor backgroundColor:(NSColor *)bgColor forFlag:(int)mask context:(int)ctxt;
131
#endif
132
 
133
/**
134
 * Similar to the methods above, but allows you to map DDLogMessage->tag to a particular color profile.
135
 * For example, you could do something like this:
136
 *
137
 * static NSString *const PurpleTag = @"PurpleTag";
138
 *
139
 * #define DDLogPurple(frmt, ...) LOG_OBJC_TAG_MACRO(NO, 0, 0, 0, PurpleTag, frmt, ##__VA_ARGS__)
140
 *
141
 * And then in your applicationDidFinishLaunching, or wherever you configure Lumberjack:
142
 *
143
 * #if TARGET_OS_IPHONE
144
 *   UIColor *purple = [UIColor colorWithRed:(64/255.0) green:(0/255.0) blue:(128/255.0) alpha:1.0];
145
 * #else
146
 *   NSColor *purple = [NSColor colorWithCalibratedRed:(64/255.0) green:(0/255.0) blue:(128/255.0) alpha:1.0];
147
 *
148
 * [[DDTTYLogger sharedInstance] setForegroundColor:purple backgroundColor:nil forTag:PurpleTag];
149
 * [DDLog addLogger:[DDTTYLogger sharedInstance]];
150
 *
151
 * This would essentially give you a straight NSLog replacement that prints in purple:
152
 *
153
 * DDLogPurple(@"I'm a purple log message!");
154
**/
155
#if TARGET_OS_IPHONE
156
- (void)setForegroundColor:(UIColor *)txtColor backgroundColor:(UIColor *)bgColor forTag:(id <NSCopying>)tag;
157
#else
158
- (void)setForegroundColor:(NSColor *)txtColor backgroundColor:(NSColor *)bgColor forTag:(id <NSCopying>)tag;
159
#endif
160
 
161
/**
162
 * Clearing color profiles.
163
**/
164
- (void)clearColorsForFlag:(int)mask;
165
- (void)clearColorsForFlag:(int)mask context:(int)context;
166
- (void)clearColorsForTag:(id <NSCopying>)tag;
167
- (void)clearColorsForAllFlags;
168
- (void)clearColorsForAllTags;
169
- (void)clearAllColors;
170
 
171
@end