While a separate formatting class will work, it will make your logging code a bit more verbose. In my project, I decided to add some additional macros that use CocoaLumberjack as follows:
// Prefix.pch file // ... #ifdef DEBUG #define DLogError(fmt, ...) DDLogError((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) #define DLogWarn(fmt, ...) DDLogWarn((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) #define DLogInfo(fmt, ...) DDLogInfo((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) #define DLogDebug(fmt, ...) DDLogDebug((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) #define DLogVerbose(fmt, ...) DDLogVerbose((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) #else #define DLogError(fmt, ...) #define DLogWarn(fmt, ...) #define DLogInfo(fmt, ...) #define DLogDebug(fmt, ...) #define DLogVerbose(fmt, ...) #endif
In the client code, you can call:
DLogWarn(@"This is a warning");
bizz84
source share