我正在尝试为Cocoa Lumberjack向我显示文件和行号的方法。
在浏览了文档和一些谷歌搜索之后,我发现没有简单的方法可以做到这一点。
有没有不添加自定义格式器的方法吗?
最佳答案
好吧,就像我说的那样,没有内置的方法。因此,我实现了自定义格式化程序:
@interface LineNumberLogFormatter : NSObject<DDLogFormatter>
- (NSString *)formatLogMessage:(DDLogMessage *)logMessage;
@end
@implementation LineNumberLogFormatter
- (NSString *)formatLogMessage:(DDLogMessage *)logMessage
{
NSString *path = [NSString stringWithCString:logMessage->file encoding:NSASCIIStringEncoding];
NSString *fileName = [path lastPathComponent];
return [NSString stringWithFormat:@"%@:%d %@", fileName, logMessage->lineNumber, logMessage->logMsg];
}
@end
关于ios - cocoa 伐木 worker : how to show file and line number?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19137867/