我正在尝试为 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/