RMLogFormatter
是一个针对 CocoaLumberjack 的可定制日志格式化工具。默认日志格式如下
yyyy-MM-dd HH:mm:ss.SSS | FILENAME:LINE_NUMBER (TID:THREAD_ID) : LOG_MESSAGE
按照以下设置日志格式化程序
RMLogFormatter *logFormatter = [[RMLogFormatter alloc] init];
[[DDTTYLogger sharedInstance] setLogFormatter:logFormatter];
[DDLog addLogger:[DDTTYLogger sharedInstance]];
可以使用 RMLogFormatterOptions
来定制日志输出中的信息。 RMLogFormatterOptions
是一个位掩码选项,它告诉 RMLogFormatter
在日志语句中包含什么以及如何格式化它。格式化器选项必须在初始化时传递
// e.g. 00:04:10.627 | Error | -[AppDelegate application:didFinishLaunchingWithOptions:]:46 : Error message
RMLogFormatterOptions options = RMLogFormatterOptionsTimestampShort |
RMLogFormatterOptionsMethodName |
RMLogFormatterOptionsLineNumber |
RMLogFormatterOptionsLogFlagLong;
RMLogFormatter *logFormatter = [[RMLogFormatter alloc] initWithOptions:options];
如果您希望日志自行表达,请将 RMLogFormatterOptionsNone
设置在 -[RMLogFormatter initWithOptions:]
的 options
参数中。
typedef NS_OPTIONS(NSUInteger, RMLogFormatterOptions) {
RMLogFormatterOptionsNone = 0,
RMLogFormatterOptionsWordWrap = 1 << 0,
RMLogFormatterOptionsTimestampShort = 1 << 1,
RMLogFormatterOptionsTimestampLong = 1 << 2,
RMLogFormatterOptionsFilePath = 1 << 3,
RMLogFormatterOptionsFileName = 1 << 4,
RMLogFormatterOptionsMethodName = 1 << 5,
RMLogFormatterOptionsLineNumber = 1 << 6,
RMLogFormatterOptionsThreadName = 1 << 7,
RMLogFormatterOptionsThreadID = 1 << 8,
RMLogFormatterOptionsLogFlagShort = 1 << 9,
RMLogFormatterOptionsLogFlagLong = 1 << 10
};
RMLogFormatter 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE。