| Jabber Guest iOS SDK

- Main Page
- Modules
- Classes

All Classes Functions Variables Enumerations Enumerator Properties Groups
CSILog.h
1 //
2 // CSILog.h
3 //
4 // Created: 12/3/08
5 //
6 // Copyright 2008 Cisco Systems, Inc., All rights reserved.
7 // 170 West Tasman Drive, San Jose, California, 95134, USA
8 //
9 // CONFIDENTIAL AND PROPRIETARY INFORMATION - DO NOT DISCLOSE
10 //
11
12
13 // Logging functions. "Trace" functions log the current method.
14 // NOTE: The following require DEBUG be defined:
15 // * Logging to both console and log files
16 // * Turning on levels below CSILogLevelDebug
17
51 #import <Foundation/Foundation.h>
52
53 #if __clang__
54 #define __CSI_PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wformat-extra-args\"")
55 #define __CSI_PRAGMA_POP_NO_EXTRA_ARG_WARNINGS _Pragma("clang diagnostic pop")
56 #else
57 #define __CSI_PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS
58 #define __CSI_PRAGMA_POP_NO_EXTRA_ARG_WARNINGS
59 #endif
60
61
62 extern NSString * CSILogMaximumLogSizeExceededNotification;
63
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67
68 extern NSString *kCSILoggingLevelDefaultsKey; // Key for userDefaults
69
70 //
71 // Log Levels
72 //
73 enum CSILogLevel
74 {
75 CSILogLevelBug = 0, // Called "INTERNAL" in the output
76 CSILogLevelError,
77 CSILogLevelWarning,
78 CSILogLevelInfo,
79 CSILogLevelDebug,
80 CSILogLevelTrace
81 };
82 typedef enum CSILogLevel CSILogLevel;
83
84 //
85 // Logging functions. All take printf-style formats
86 // Remember, you can't inline varargs, so don't try.
87 // Note that this format attribute isn't as powerful as the __printf__ one.
88 // It won't protect you against type-mismatch as much as you'd like, but as
89 // they improve the compiler, it may someday.
90 void CSILogMessage(CSILogLevel level, NSString *message, ...) __attribute__((format(__NSString__, 2, 3)));
91
92 //
93 // A pre-formatted string to print out. This is to be used by components that would normally printf to the Console
94 //
95 void CSILogConsoleMessage(CSILogLevel, const char* message);
96
97 // Similar to CSILogDebugTrace(), but for the calling function/method of the currently executing method that calls this method.
98 // NOTE: This call is extremely expensive, use with discretion.
99 // NOTE: ikono - 2011.06.09 - Not sure this is compatable with iOS use at your own risk.
100 void CSILogDebugCallerWithMessage(NSString *message, BOOL isPrefix);
101
102 // Log a message to analytics (CUET).
103 // WARNING: The message should not contain any private or identifiable information.
104 // You must anonymize user names, phone numbers, URLs, etc.
105 void CSILogAnalyticsMessage(CSILogLevel level, NSString *message);
106
107 #define CSILogBug(format, args...) CSILogMessage(CSILogLevelBug, format , ## args)
108 #define CSILogError(format, args...) CSILogMessage(CSILogLevelError, @"%s < " format " > %s %d" , __FUNCTION__, ## args , __FILE__, __LINE__)
109 #define CSILogWarning(format, args...) CSILogMessage(CSILogLevelWarning, @"%s < " format " > %s %d" , __FUNCTION__, ## args , __FILE__, __LINE__)
110 #define CSILogInfo(format, args...) CSILogMessage(CSILogLevelInfo, @"%s < " format " > %s %d" , __FUNCTION__, ## args , __FILE__, __LINE__)
111 #define CSILogDebug(format, args...) CSILogMessage(CSILogLevelDebug, @"%s < " format " > %s %d" , __FUNCTION__, ## args , __FILE__, __LINE__)
112 #define CSILogDebugTrace() CSILogDebug(@"%@", [NSString stringWithUTF8String:__func__])
113 #define LOG_ENTRY(F, ...) CSILogDebug(@"entry [" F "]", ##__VA_ARGS__)
114 #define LOG_EXIT() CSILogDebug(@"exit")
115
116 // Similar to CSILogDebugTrace(), but for the calling function/method of the currently executing method that calls this method.
117 // NOTE: This call is extremely expensive, use with discretion.
118 #define CSILogDebugCallerTrace() CSILogDebugCallerWithMessage([NSString stringWithFormat:@"%@ called by ", [NSString stringWithUTF8String:__func__]], YES)
119 #define JSL(fmt,...) NSLog((@"%s [Line %d] " fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__);
120 #ifdef __cplusplus
121 }
122 #endif
123
124 // CSIAssert() macros work exactly like NSAssert() macros except that they also log, even in release mode
125
126 #define _CSIAssertBody(condition, desc, arg1, arg2, arg3, arg4, arg5) \
127 if (!(condition)) { \
128 __CSI_PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS \
129 CSILogBug((desc), (arg1), (arg2), (arg3), (arg4), (arg5)); \
130 __CSI_PRAGMA_POP_NO_EXTRA_ARG_WARNINGS \
131 _NSAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), (arg5)); \
132 }
133
134 #define CSIAssert5(condition, desc, arg1, arg2, arg3, arg4, arg5) \
135 _CSIAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), (arg5))
136
137 #define CSIAssert4(condition, desc, arg1, arg2, arg3, arg4) \
138 _CSIAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), 0)
139
140 #define CSIAssert3(condition, desc, arg1, arg2, arg3) \
141 _CSIAssertBody((condition), (desc), (arg1), (arg2), (arg3), 0, 0)
142
143 #define CSIAssert2(condition, desc, arg1, arg2) \
144 _CSIAssertBody((condition), (desc), (arg1), (arg2), 0, 0, 0)
145
146 #define CSIAssert1(condition, desc, arg1) \
147 _CSIAssertBody((condition), (desc), (arg1), 0, 0, 0, 0)
148
149 #define CSIAssert(condition, desc) \
150 _CSIAssertBody((condition), (desc), 0, 0, 0, 0, 0)
151
152
153 // CSICAssert() macros work exactly like NSCAssert() macros except that they also log, even in release mode
154 #define _CSICAssertBody(condition, desc, arg1, arg2, arg3, arg4, arg5) \
155 if (!(condition)) { \
156 __CSI_PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS \
157 CSILogBug((desc), (arg1), (arg2), (arg3), (arg4), (arg5)); \
158 __CSI_PRAGMA_POP_NO_EXTRA_ARG_WARNINGS \
159 _NSCAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), (arg5)); \
160 }
161
162 #define CSICAssert5(condition, desc, arg1, arg2, arg3, arg4, arg5) \
163 _CSICAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), (arg5))
164
165 #define CSICAssert4(condition, desc, arg1, arg2, arg3, arg4) \
166 _CSICAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), 0)
167
168 #define CSICAssert3(condition, desc, arg1, arg2, arg3) \
169 _CSICAssertBody((condition), (desc), (arg1), (arg2), (arg3), 0, 0)
170
171 #define CSICAssert2(condition, desc, arg1, arg2) \
172 _CSICAssertBody((condition), (desc), (arg1), (arg2), 0, 0, 0)
173
174 #define CSICAssert1(condition, desc, arg1) \
175 _CSICAssertBody((condition), (desc), (arg1), 0, 0, 0, 0)
176
177 #define CSICAssert(condition, desc) \
178 _CSICAssertBody((condition), (desc), 0, 0, 0, 0, 0)
179
181
182 #define CSIAbstract() CSIAssert1(NO, @"Called abstract method: %s", __func__)
183
184 //
185 // CSILog
186 //
187 @class CSIAnalytics;
188
189 @interface CSILog : NSObject
190 {
191 NSString *myLogDirectory;
192 NSString *myLogName;
193 NSString *myLogBasename;
194 NSFileHandle *myFileHandle;
195 CSILogLevel myLevel;
196 NSDateFormatter *myDateFormatter;
197 NSThread *myThread;
198 BOOL myIsStarted;
199 NSTimeInterval myMaximumLogAge;
200 NSUInteger myMaximumLogSize;
201 CSIAnalytics *myAnalytics;
202 BOOL mySuppressRepeatedMessages;
203 NSString *myLastWrittenMessage;
204 NSUInteger myRepeatedMessageCount;
205 BOOL myClearLogs;
206 BOOL myLoggingRestarted;
207 }
208
209 // These are intentionally atomic to remind you that these are accessed on multiple threads.
210 // Atomicy doesn't actually matter for non-objects.
211 @property (readwrite, assign) CSILogLevel logLevel;
212 @property (readwrite, assign) BOOL isStarted;
213 @property (readwrite, assign) NSTimeInterval maximumLogAge;
214 @property (readwrite, assign) NSUInteger maximumLogSize; //bytes
215 @property (readwrite, retain) NSThread *thread;
216 @property (readwrite, retain) NSDateFormatter *dateFormatter;
217 @property (nonatomic, readwrite, retain) CSIAnalytics *analytics;
218 @property (nonatomic, readwrite, assign) BOOL suppressRepeatedMessages;
219 //@property (readwrite, retain) NSString *logDirectory;
220
221
222 // Shared instance
223 + (id)sharedLog;
224 + (void)setSharedLog:(CSILog *)log;
225
232 - (id)initWithDirectory:(NSString *)directory logName:(NSString *)logName;
233
238 - (void)startLogging;
239
244 - (void)stopLogging;
245
250 - (void)restartLogging;
251
256 - (void)logMessage:(NSString *)message level:(CSILogLevel)level;
257
264 - (void)removeOldLogs;
265
270 - (void)removeAllLogs;
271
275 - (BOOL)didReachMaxLogSize;
276
277
281 - (NSArray *) getAllLogsFullPathName;
282
283 @end