Cocoa Lumberjack:如何显示文件和行号? [英] Cocoa Lumberjack: how to show file and line number?

查看:164
本文介绍了Cocoa Lumberjack:如何显示文件和行号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到 Cocoa Lumberjack 的方式来显示我的文件和行号。

I am trying to find a way for Cocoa Lumberjack to show me file and line number.

在查看文档和一些Google搜索后,我发现没有简单的方法来做到这一点。

After looking through the docs and some Googling, I found no easy way to do this.

有没有办法做这个没有添加自定义格式化程序?

Is there any way to do this without adding custom formatter?

推荐答案

好吧,就像我说的,没有内置的方式。所以,我实现了自定义格式化程序:

Well, like I said, there is no built-in way. So, I've implemented custom formatter:

@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

这篇关于Cocoa Lumberjack:如何显示文件和行号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆