-
Notifications
You must be signed in to change notification settings - Fork 3
/
MCCLumberJack.h
158 lines (114 loc) · 6.89 KB
/
MCCLumberJack.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//
// MCCLumberJack.h
// Logging Framework enabler
//
// Created by Scott Little on 29/5/14.
// Copyright (c) 2014 Little Known Software, Inc. All rights reserved.
//
#import "MCCCommonHeader.h"
#ifdef LOG_LEVEL_DEF
#undef LOG_LEVEL_DEF
#endif
extern int MCC_PREFIXED_NAME(DDDebugLevel);
#define LOG_LEVEL_DEF MCC_PREFIXED_NAME(DDDebugLevel)
extern int MCC_PREFIXED_NAME(DDLogFeatures);
extern int MCC_PREFIXED_NAME(DDLogBugs);
@interface MCC_PREFIXED_NAME(LumberJack) : NSObject
+ (void)addStandardLoggersWithFeatureDict:(NSDictionary *)featureDict;
+ (void)addStandardLoggersWithFeatureDict:(NSDictionary *)featureDict forBundleId:(NSString *)aBundleId;
+ (void)addBugLoggerWithDict:(NSDictionary *)bugDict forBundleId:(NSString *)aBundleId;
+ (int)debugLevel;
+ (void)setDebugLevel:(int)newLevel;
+ (void)addLogFeature:(int)newFeature;
+ (void)addLogBug:(int)newBug;
@end
#pragma mark - MCC Macros
#define MCCSecureFormattingContext (1 << 1)
#define MCCFeatureFormattingContext (1 << 2)
#define MCCBugFormattingContext (1 << 3)
#define MCCErr(frmt, ...) LOG_OBJC_MAYBE(LOG_ASYNC_ERROR, LOG_LEVEL_DEF, LOG_FLAG_ERROR, 0, frmt, ##__VA_ARGS__)
#define MCCErrC(frmt, ...) LOG_C_MAYBE(LOG_ASYNC_ERROR, LOG_LEVEL_DEF, LOG_FLAG_ERROR, 0, frmt, ##__VA_ARGS__)
#define MCCWarn(frmt, ...) LOG_OBJC_MAYBE(LOG_ASYNC_WARN, LOG_LEVEL_DEF, LOG_FLAG_WARN, 0, frmt, ##__VA_ARGS__)
#define MCCInfo(frmt, ...) LOG_OBJC_MAYBE(LOG_ASYNC_INFO, LOG_LEVEL_DEF, LOG_FLAG_INFO, 0, frmt, ##__VA_ARGS__)
#define MCCDebug(frmt, ...) LOG_OBJC_MAYBE(LOG_ASYNC_DEBUG, LOG_LEVEL_DEF, LOG_FLAG_DEBUG, 0, frmt, ##__VA_ARGS__)
#define MCCLogC(frmt, ...) LOG_C_MAYBE(LOG_ASYNC_VERBOSE, LOG_LEVEL_DEF, LOG_FLAG_VERBOSE, 0, frmt, ##__VA_ARGS__)
#define MCCLog(frmt, ...) LOG_OBJC_MAYBE(LOG_ASYNC_VERBOSE, LOG_LEVEL_DEF, LOG_FLAG_VERBOSE, 0, frmt, ##__VA_ARGS__)
#define MCCLogFeature(featureFlag, frmt, ...) LOG_OBJC_MAYBE(LOG_ASYNC_VERBOSE, MCC_PREFIXED_NAME(DDLogFeatures), featureFlag, MCCFeatureFormattingContext, frmt, ##__VA_ARGS__)
#define MCCLogBug(bugFlag, frmt, ...) LOG_OBJC_MAYBE(LOG_ASYNC_VERBOSE, MCC_PREFIXED_NAME(DDLogBugs), bugFlag, MCCBugFormattingContext, frmt, ##__VA_ARGS__)
#ifdef MCC_INSECURE_LOGS
#define DEFAULT_CONTEXT 0
#else
#define DEFAULT_CONTEXT MCCSecureFormattingContext
#endif
#define LOG_MACRO_SEC(isAsynchronous, lvl, flg, ctx, fnct, frmt, ...) \
[DDLog secureLog:isAsynchronous level:lvl flag:flg context:ctx file:__FILE__ function:fnct line:__LINE__ tag:nil format:(frmt), ##__VA_ARGS__]
#define LOG_MAYBE_SEC(async, lvl, flg, ctx, fnct, frmt, ...) \
do { if(lvl & flg) LOG_MACRO_SEC(async, lvl, flg, ctx, fnct, frmt, ##__VA_ARGS__); } while(0)
#define LOG_OBJC_MAYBE_SEC(async, lvl, flg, ctx, frmt, ...) \
LOG_MAYBE_SEC(async, lvl, flg, ctx, sel_getName(_cmd), frmt, ##__VA_ARGS__)
#define LOG_C_MAYBE_SEC(async, lvl, flg, ctx, frmt, ...) \
LOG_MAYBE_SEC(async, lvl, flg, ctx, __FUNCTION__, frmt, ##__VA_ARGS__)
#define FEATURE_LOGGED(flg) \
(MCC_PREFIXED_NAME(DDLogFeatures) & flg)
#define BUG_LOGGED(flg) \
(MCC_PREFIXED_NAME(DDLogBugs) & flg)
#define MCCErrS(frmt, ...) LOG_OBJC_MAYBE_SEC(LOG_ASYNC_ERROR, LOG_LEVEL_DEF, LOG_FLAG_ERROR, DEFAULT_CONTEXT, frmt, ##__VA_ARGS__)
#define MCCErrCS(frmt, ...) LOG_C_MAYBE_SEC(LOG_ASYNC_ERROR, LOG_LEVEL_DEF, LOG_FLAG_ERROR, DEFAULT_CONTEXT, frmt, ##__VA_ARGS__)
#define MCCWarnS(frmt, ...) LOG_OBJC_MAYBE_SEC(LOG_ASYNC_WARN, LOG_LEVEL_DEF, LOG_FLAG_WARN, DEFAULT_CONTEXT, frmt, ##__VA_ARGS__)
#define MCCInfoS(frmt, ...) LOG_OBJC_MAYBE_SEC(LOG_ASYNC_INFO, LOG_LEVEL_DEF, LOG_FLAG_INFO, DEFAULT_CONTEXT, frmt, ##__VA_ARGS__)
#define MCCDebugS(frmt, ...) LOG_OBJC_MAYBE_SEC(LOG_ASYNC_DEBUG, LOG_LEVEL_DEF, LOG_FLAG_DEBUG, DEFAULT_CONTEXT, frmt, ##__VA_ARGS__)
#define MCCLogS(frmt, ...) LOG_OBJC_MAYBE_SEC(LOG_ASYNC_VERBOSE, LOG_LEVEL_DEF, LOG_FLAG_VERBOSE, DEFAULT_CONTEXT, frmt, ##__VA_ARGS__)
#define MCCLogFeatureS(featureFlag, frmt, ...) LOG_OBJC_MAYBE_SEC(LOG_ASYNC_VERBOSE, MCC_PREFIXED_NAME(DDLogFeatures), featureFlag, (DEFAULT_CONTEXT | MCCFeatureFormattingContext), frmt, ##__VA_ARGS__)
#define MCCLogBugS(bugFlag, frmt, ...) LOG_OBJC_MAYBE_SEC(LOG_ASYNC_VERBOSE, MCC_PREFIXED_NAME(DDLogBugs), bugFlag, (DEFAULT_CONTEXT | MCCBugFormattingContext), frmt, ##__VA_ARGS__)
#ifdef DEBUG
#define MCCAssertLog(s, ...) do {MCCErr(s, ##__VA_ARGS__);[[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:s, ##__VA_ARGS__];} while (0);
#else
#define MCCAssertLog(s, ...) MCCErr(s, ##__VA_ARGS__)
#endif
// Assertion that will simply log in Production code
#define MCCAssert(condition, frmt, ...) do { if (!(condition)) { MCCAssertLog(frmt, ##__VA_ARGS__); }} while(0)
#pragma mark - LumberJack Mappings
// From DDLog.h
// Classes
#define DDLog MCC_PREFIXED_NAME(DDLog)
#define DDLogMessage MCC_PREFIXED_NAME(DDLogMessage)
#define DDAbstractLogger MCC_PREFIXED_NAME(DDAbstractLogger)
#define DDLoggerNode MCC_PREFIXED_NAME(DDLoggerNode)
// Protocols
#define DDLogger MCC_PREFIXED_NAME(DDLogger)
#define DDLogFormatter MCC_PREFIXED_NAME(DDLogFormatter)
#define DDRegisteredDynamicLogging MCC_PREFIXED_NAME(DDRegisteredDynamicLogging)
// Other Symbols
#define DDExtractFileNameWithoutExtension MCC_PREFIXED_NAME(DDExtractFileNameWithoutExtension)
#define DDLogMessageOptions MCC_PREFIXED_NAME(DDLogMessageOptions)
#define DDLogMessageCopyFile MCC_PREFIXED_NAME(DDLogMessageCopyFile)
#define DDLogMessageCopyFunction MCC_PREFIXED_NAME(DDLogMessageCopyFunction)
// From DDFileLogger
// Classes
#define DDLogFileManagerDefault MCC_PREFIXED_NAME(DDLogFileManagerDefault)
#define DDLogFileFormatterDefault MCC_PREFIXED_NAME(DDLogFileFormatterDefault)
#define DDFileLogger MCC_PREFIXED_NAME(DDFileLogger)
#define DDLogFileInfo MCC_PREFIXED_NAME(DDLogFileInfo)
// Protocols
#define DDLogFileManager MCC_PREFIXED_NAME(DDLogFileManager)
// From DDTTYLogger
// Classes
#define DDTTYLogger MCC_PREFIXED_NAME(DDTTYLogger)
#define DDTTYLoggerColorProfile MCC_PREFIXED_NAME(DDTTYLoggerColorProfile)
// From DDASLLogger
// Classes
#define DDASLLogger MCC_PREFIXED_NAME(DDASLLogger)
// From DDASLLogCapture
// Classes
#define DDASLLogCapture MCC_PREFIXED_NAME(DDASLLogCapture)
// From DDAbstractDatabaseLogger
// Classes
#define DDAbstractDatabaseLogger MCC_PREFIXED_NAME(DDAbstractDatabaseLogger)
// From CLIColor (support file)
// Classes
#define CLIColor MCC_PREFIXED_NAME(CLIColor)
// Needs to go here to ensure that the defines above are loaded first
#include "DDLog.h"
@interface DDLog (MCCLumberJack)
+ (void)secureLog:(BOOL)asynchronous level:(int)level flag:(int)flag context:(int)context file:(const char *)file function:(const char *)function line:(int)line tag:(id)tag format:(NSString *)format, ...;
@end