问题描述
我在iPhone项目中使用来记录一些信息。
I'm using CocoaLumberjack in an iPhone project, to log some information.
我已按照,一切正常,但有一件事让我感到困惑:似乎没有一种优雅的方式来定义整个应用程序的日志级别。为了使它工作,我需要在每个源文件中定义一个常量,如下所示:
I've followed the Getting started guide, and everything works fine, but there is one thing that bugs me: there doesn't seem to be an elegant way to define a log level for the whole app. To make it work I need to define a constant in every source file, like this:
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
那么,有没有办法为应用程序定义全局日志级别?
So, is there a way to define a global log level for the application?
我找到了,但我仍然需要在每个文件中添加一个#import ...
I found this article on the subject, but I still need to add an #import in every file...
推荐答案
我没有找到比。
Constant.h
extern int const ddLogLevel;
Constant.m
#import "Constants.h"
#import "DDLog.h"
int const ddLogLevel = LOG_LEVEL_VERBOSE;
记录器配置
#import "DDLog.h"
#import "DDASLLogger.h"
#import "DDTTYLogger.h"
#import "DDFileLogger.h"
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[DDLog addLogger:[DDASLLogger sharedInstance]];
[DDLog addLogger:[DDTTYLogger sharedInstance]];
DDFileLogger *fileLogger = [[DDFileLogger alloc] init];
[DDLog addLogger:fileLogger];
[fileLogger release];
...
导入课程
#import "DDLog.h"
#import "Constants.h"
...
- (void)someMethod {
DDLogVerbose(@"Log this message");
}
这篇关于CocoaLumberjack的全局日志级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!