RMLogFormatter 0.1.3

RMLogFormatter 0.1.3

测试已测试
语言语言 Objective-CObjective C
许可证 MIT
发布最后发布2015 年 5 月

Ryan Maloney 维护。



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 参数中。

RMLogFormatterOptions

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。