ios - cocoa 伐木 worker : how to show file and line number?

标签 ios objective-c macos debugging cocoalumberjack

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

相关文章:

ios - 关闭一个 View Controller,然后呈现一个 Alert Controller

java - 修复 Zxing (Obj-C) 中的 Aztec 解码器以返回原始 ByteArray

ios - 使用 AFNetworking 加载图像 - 调整大小

objective-c - 点击 Storyboard中的按钮时的不同图像

android - 使用glOrthof的OpenglES多平台屏幕比例解决方案

ios - 跳出循环调用数组

ios - MVC : Where do I place custom UICollectionCell

php - 在 Mac 10.6 上使用 Mamp 或其他包与手动启用 PHP 并安装 MySQL

macos - NSImage 和视网膜显示混淆

python - Python 中特定于操作系统的命名空间规则