使用Cocoa Lumberjack日志框架立即刷新日志语句,即NSLog刷新到控制台的方式 [英] Immediately flushing log statements using the Cocoa Lumberjack logging framework, the way NSLog flushes to console

查看:175
本文介绍了使用Cocoa Lumberjack日志框架立即刷新日志语句,即NSLog刷新到控制台的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多iOS开发人员已经找到了 Cocoa Lumberjack Logging framework 来满足简单 NSLog 语句没有。它让人想起Java世界中的Log4J。

Many iOS developers have found the Cocoa Lumberjack Logging framework to fill a need that simple NSLog statements don't. It's reminiscent of Log4J in the Java world.

无论如何,我已经为Lumberjack编写了自己的自定义格式化程序,但我看不到有关如何使用的任何文档立即刷新日志语句。

In any event, I have written my own custom formatter for Lumberjack, but what I don't see is any documentation on how to flush log statements immediately.

例如,如果我走过调试器并点击 NSLog()语句,它立即将日志语句刷新到控制台。这就是我想从Lumberjack中的 DDLogVerbose()调用获得的行为。

For example, if I'm walking through the debugger and I hit an NSLog() statement, it flushes the log statement to the console immediately. That's the behavior I'd like to get from a DDLogVerbose() call in Lumberjack.

现在,我返回并将这些语句更改为 NSLog()语句,如果我希望它们在我调试一段代码时立即吐出。由于Lumberjack如此强大,我认为有一种方法可以将其配置为无延迟地冲洗。

Right now, I go back and change these statements to NSLog() statements if I want them to spit out immediately as I'm debugging a segment of code. With Lumberjack being so robust, I got to think there's a way to configure it to flush with no delay.

任何人都知道如何制作它?

Anyone know how to make it so?

推荐答案

我在 DDLog.h 文件中找到了答案。 Lumberjack具有异步和同步日志记录的概念。在初次阅读时,它没有让我知道这是为了什么。

I found the answer in the DDLog.h file. Lumberjack has the concept of asynchronous and synchronous logging. At initial read, it didn't hit me as to what this was for.

基本上,如果你想按顺序输出日志语句,你需要制作它同步(但是,正如迈克所说,这会降低性能)。因此,这应该只在调试情况下完成。理想情况下,我会将另一个标头放在一起和/或其他一些预处理器宏,以确保我不会将开关同步打开。

Basically, if you want the log statement to be output in sequence, one needs to make it synchronized (though, as Mike mentioned, this will slow down performance). So, this should only be done in a debugging situation. Ideally, I'll put another header together and/or some other pre-processor macro to ensure I don't leave the switch flipped on as synchronous.

这是你的意思执行:


  1. 打开 DDLog.h

  2. 使用 #define LOG_ASYNC_ENABLED YES 转到该行。您可以在一个位置将此更改为以进行同步日志记录,或者您可以在后面的行中更改各个级别。

  1. Open up DDLog.h
  2. Go to the line with #define LOG_ASYNC_ENABLED YES. You can change this to NO in one spot for synchronous logging across the board, or you can change individual levels, in the lines that follow.

请注意,标题不鼓励更改DDLog.h文件本身。因此,按照Lumberjack维基页面链接上的说明,他们将解释如何使用不同的头文件来表达这些覆盖自定义。

Note that the header discourages changing the DDLog.h file itself. So, following the instructions on the Lumberjack wiki page link, they explain how to use a different header file to articulate these override customizations.

使用它,这是我成功编写和测试的内容,作为我在应用程序的预编译头中导入的MyAppLumberjack.h头文件:

Using that, here's what I've successfully written and tested, as "MyAppLumberjack.h" header file that I import in my app's precompiled header:

#import "DDLog.h"
#import "DDASLLogger.h"
#import "DDTTYLogger.h"

// ========================= Overrides ========================================
// --> per https://github.com/robbiehanson/CocoaLumberjack/wiki/CustomLogLevels
// ----------------------------------------------------------------------------

// Are we in an optimized (i.e. Release) build?
#ifdef __OPTIMIZE__
    // YES: Nothing to do from the default. (You could simplify this by using #ifndef above instead)
#else
    // NO: We're in a Debug build. As such, let's configure logging to flush right away.
    // Undefine the asynchronous defaults:
    #undef LOG_ASYNC_VERBOSE
    #undef LOG_ASYNC_INFO
    #undef LOG_ASYNC_WARN

    // Define the logs levels to be synchronous:
    #define LOG_ASYNC_VERBOSE   (NO && LOG_ASYNC_ENABLED)   // Debug logging will be synchronous
    #define LOG_ASYNC_INFO      (NO && LOG_ASYNC_ENABLED)   // Info logging will be synchronous
    #define LOG_ASYNC_WARN      (NO && LOG_ASYNC_ENABLED)   // Warn logging will be synchronous
#endif

这篇关于使用Cocoa Lumberjack日志框架立即刷新日志语句,即NSLog刷新到控制台的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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