繁体   English   中英

CocoaLumberjack日志级别

[英]CocoaLumberjack log level

我不太了解日志级别的含义。

在Lumbejack中,定义了以下日志级别:

#define LOG_LEVEL_OFF     DDLogLevelOff
#define LOG_LEVEL_ERROR   DDLogLevelError
#define LOG_LEVEL_WARN    DDLogLevelWarning
#define LOG_LEVEL_INFO    DDLogLevelInfo
#define LOG_LEVEL_DEBUG   DDLogLevelDebug
#define LOG_LEVEL_VERBOSE DDLogLevelVerbose
#define LOG_LEVEL_ALL     DDLogLevelAll

这些是什么意思? 以及如何使用它们? 与CocoaLumberjack相关的都是iOS版吗?

另外,我在pch文件中使用以下代码:

#ifdef DEBUG
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
#else
static const int ddLogLevel = LOG_LEVEL_ERROR;
#endif

那是什么意思 我在项目中搜索了ddLogLevel var,但没有在任何地方使用它。 另外,不要在伐木工人豆荚中。

设置ddLogLevel过滤来自各种DDLogXXX方法的消息。

如果将ddLogLevel设置为LOG_LEVEL_ALL则将记录所有DDLogXXX方法。 如果将ddLogLevel设置为LOG_LEVEL_INFO则仅记录InfoWarningError

只需查看显示的#define行列表即可。 选择给定值只会导致该级别的消息以及列表中较高级别的消息。

如果将ddLogLevel设置为LOG_LEVEL_INFO ,则有以下两行:

DDLogInfo("some info message");
DDLogDebug("some debug message");

然后,由于Debug低于Info因此仅记录第一条消息。

每个级别的实际含义都有些主观。 只需在您的应用中一致地使用它们即可。 最重要或最重要的消息应具有最高级别,而最不重要的消息应具有较低级别。

当我的应用遇到意外值或提供NSError参数的方法失败时,我使用DDLogError 我记录了一条相关消息,并包含NSError值。

我将DDLogInfo用于“我在这里”类型的消息。

我使用DDLogDebug记录变量值。

我不经常使用DDLogWarn但是您可以将其用于没有实际错误但需要注意的意外问题。

这些是不同程度的日志记录粒度。 LOG_LEVEL_ALL表示将任何日志写入伐木工人使用的控制台和文件。 LOG_LEVEL_OFF是没有日志记录的极端的另一端。 您可以使用它们来确定要显示哪种版本的日志。 以下是一些用例示例。

- (void)viewDidLoad
{
    [super viewDidLoad];

    // this log isn't particularly useful for a production build, 
    // but can be helpful when debugging. So we use verbose.
    DDLogVerbose(@"This view controller loaded");
}

- (void)didRecieveMemoryWarning
{
    // This is a bad situation, but it isn't an error really.
    // Just a signal that we need to free up memory. So we use warning.
    DDLogWarning(@"We are using too much memory.");
}

- (void)doSomething
{
    NSError *error;
    [self doSomethingElse:&error];
    if (error) {
        // This is definitely an error we need to handle. If you have to
        // look through crash logs on a production build, you definitely
        // want this log to show up there.
        DDLogError(@"Encountered an error: %@", error);
    }
}

在这些示例中,当您从Xcode运行应用程序时,将显示所有日志,但是在生产崩溃日志中将仅显示错误日志。 ddLogLevel常数是您确定所需的日志记录级别的方式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM