TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Oct 2015 |
Maintained by Takanori Ishikawa.
K9LogPatternFormatter is flexible logging message formatter configurable with pattern string (inspired by Log4j PatternLayout). It includes a formatter implementation for CocoaLumberjack. Writing a new formatter for other framework is easy.
#import <CocoaLumberjack/CocoaLumberjack.h>
#import <K9LogPatternFormatter/K9LogLumberjackPatternFormatter.h>
...
id<DDLogger> consoleLogger = [DDTTYLogger sharedInstance];
consoleLogger.logFormatter = [[K9LogLumberjackPatternFormatter alloc] initWithPattern:@"%.1p: %m"];
[DDLog addLogger:consoleLogger];
Supported patterns:
%d{pattern}
timestamp formatted by using NSDateFormatter
%d{HH':'mm':'ss}
prints 14:34:02
%d{ISO8601}
prints 2014-03-12 14:34:02,781
%d{ISO8601_BASIC}
prints 20140312 143402,781
%d{ABSOLUTE}
prints 14:34:02,781
%d{DATE}
prints 12 Mar 2014 14:34:02,781
%d{COMPACT}
prints 20140312143402781
ISO8601
is used.%m
message%p
log level%F
file name without extension%l
file path%L
line number%M
function or method name%%
single percent sign ('%'
)Min/max width modifier is also supported:
%20m
Left pad with spaces and min width = 20%-5m
Right pad with spaces and min width = 5%.10m
Truncate if message is longer than 10%-5.10m
Right pad with spaces and min:5, max:10For example, if the conversion pattern is @"[%-5p] %d{HH':'mm':'ss} %m"
, it would yield the output:
[DEBUG] 00:45:20 Message1
[WARN ] 00:45:21 Message2
@"%.1p: %m at %F:%L"
would yield:
D: Message1 at File1:15
W: Message2 at File2:32
If you want formatter for CocoaLumberjack, in your Podfile:
pod "K9LogPatternFormatter/Lumberjack"
or, you can grab core classes to writting your own formatter:
pod "K9LogPatternFormatter/Core"
MIT license