added ability to tag logs for easier filtering

This commit is contained in:
Diego Waxemberg
2015-02-24 00:03:21 -05:00
parent ea231e16b6
commit 81c84597c8
2 changed files with 23 additions and 4 deletions
+1
View File
@@ -24,5 +24,6 @@ typedef enum {
#define PRFX_ERROR @"<ERROR>" #define PRFX_ERROR @"<ERROR>"
void Log(LogLevel level, NSString* fmt, ...); void Log(LogLevel level, NSString* fmt, ...);
void LogTag(LogLevel level, NSString* tag, NSString* fmt, ...);
#endif #endif
+22 -4
View File
@@ -8,7 +8,23 @@
#import "Logger.h" #import "Logger.h"
void LogTagv(LogLevel level, NSString* tag, NSString* fmt, va_list args);
void Log(LogLevel level, NSString* fmt, ...) { void Log(LogLevel level, NSString* fmt, ...) {
va_list args;
va_start(args, fmt);
LogTagv(level, NULL, fmt, args);
va_end(args);
}
void LogTag(LogLevel level, NSString* tag, NSString* fmt, ...) {
va_list args;
va_start(args, fmt);
LogTagv(level, tag, fmt, args);
va_end(args);
}
void LogTagv(LogLevel level, NSString* tag, NSString* fmt, va_list args) {
NSString* levelPrefix = @""; NSString* levelPrefix = @"";
switch(level) { switch(level) {
@@ -27,9 +43,11 @@ void Log(LogLevel level, NSString* fmt, ...) {
default: default:
break; break;
} }
NSString* prefixedString = [NSString stringWithFormat:@"%@ %@", levelPrefix, fmt]; NSString* prefixedString;
va_list args; if (tag) {
va_start(args, fmt); prefixedString = [NSString stringWithFormat:@"%@ (%@) %@", levelPrefix, tag, fmt];
} else {
prefixedString = [NSString stringWithFormat:@"%@ %@", levelPrefix, fmt];
}
NSLogv(prefixedString, args); NSLogv(prefixedString, args);
va_end(args);
} }