51 #import <Foundation/Foundation.h>
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")
57 #define __CSI_PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS
58 #define __CSI_PRAGMA_POP_NO_EXTRA_ARG_WARNINGS
62 extern NSString * CSILogMaximumLogSizeExceededNotification;
68 extern NSString *kCSILoggingLevelDefaultsKey;
82 typedef enum CSILogLevel CSILogLevel;
90 void CSILogMessage(CSILogLevel level, NSString *message, ...) __attribute__((format(__NSString__, 2, 3)));
95 void CSILogConsoleMessage(CSILogLevel, const
char* message);
100 void CSILogDebugCallerWithMessage(NSString *message, BOOL isPrefix);
105 void CSILogAnalyticsMessage(CSILogLevel level, NSString *message);
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")
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__);
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)); \
134 #define CSIAssert5(condition, desc, arg1, arg2, arg3, arg4, arg5) \
135 _CSIAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), (arg5))
137 #define CSIAssert4(condition, desc, arg1, arg2, arg3, arg4) \
138 _CSIAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), 0)
140 #define CSIAssert3(condition, desc, arg1, arg2, arg3) \
141 _CSIAssertBody((condition), (desc), (arg1), (arg2), (arg3), 0, 0)
143 #define CSIAssert2(condition, desc, arg1, arg2) \
144 _CSIAssertBody((condition), (desc), (arg1), (arg2), 0, 0, 0)
146 #define CSIAssert1(condition, desc, arg1) \
147 _CSIAssertBody((condition), (desc), (arg1), 0, 0, 0, 0)
149 #define CSIAssert(condition, desc) \
150 _CSIAssertBody((condition), (desc), 0, 0, 0, 0, 0)
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)); \
162 #define CSICAssert5(condition, desc, arg1, arg2, arg3, arg4, arg5) \
163 _CSICAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), (arg5))
165 #define CSICAssert4(condition, desc, arg1, arg2, arg3, arg4) \
166 _CSICAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), 0)
168 #define CSICAssert3(condition, desc, arg1, arg2, arg3) \
169 _CSICAssertBody((condition), (desc), (arg1), (arg2), (arg3), 0, 0)
171 #define CSICAssert2(condition, desc, arg1, arg2) \
172 _CSICAssertBody((condition), (desc), (arg1), (arg2), 0, 0, 0)
174 #define CSICAssert1(condition, desc, arg1) \
175 _CSICAssertBody((condition), (desc), (arg1), 0, 0, 0, 0)
177 #define CSICAssert(condition, desc) \
178 _CSICAssertBody((condition), (desc), 0, 0, 0, 0, 0)
182 #define CSIAbstract() CSIAssert1(NO, @"Called abstract method: %s", __func__)
189 @interface CSILog : NSObject
191 NSString *myLogDirectory;
193 NSString *myLogBasename;
194 NSFileHandle *myFileHandle;
196 NSDateFormatter *myDateFormatter;
199 NSTimeInterval myMaximumLogAge;
200 NSUInteger myMaximumLogSize;
201 CSIAnalytics *myAnalytics;
202 BOOL mySuppressRepeatedMessages;
203 NSString *myLastWrittenMessage;
204 NSUInteger myRepeatedMessageCount;
206 BOOL myLoggingRestarted;
211 @property (readwrite, assign) CSILogLevel logLevel;
212 @property (readwrite, assign) BOOL isStarted;
213 @property (readwrite, assign) NSTimeInterval maximumLogAge;
214 @property (readwrite, assign) NSUInteger maximumLogSize;
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;
224 + (void)setSharedLog:(CSILog *)log;
232 - (id)initWithDirectory:(NSString *)directory logName:(NSString *)logName;
238 - (void)startLogging;
250 - (void)restartLogging;
256 - (void)logMessage:(NSString *)message level:(CSILogLevel)level;
264 - (void)removeOldLogs;
270 - (void)removeAllLogs;
275 - (BOOL)didReachMaxLogSize;
281 - (NSArray *) getAllLogsFullPathName;