2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include <NGExtensions/NGExtensions.h>
27 #include "NGLogEvent.h"
28 #include "NGLogAppender.h"
31 @implementation NGLogger
34 self = [self initWithLogLevel:NGLogLevelAll];
38 - (id)initWithLogLevel:(NGLogLevel)_level {
39 if((self = [super init])) {
41 NSString *appenderClassName;
43 [self setLogLevel:_level];
45 #warning ** remove this as soon as we have a config
46 ud = [NSUserDefaults standardUserDefaults];
47 appenderClassName = [ud stringForKey:@"NGLogDefaultAppenderClass"];
48 if(appenderClassName == nil)
49 appenderClassName = @"NGLogConsoleAppender";
50 self->_appender = [[NSClassFromString(appenderClassName) alloc] init];
56 [self->_appender release];
61 - (void)setLogLevel:(NGLogLevel)_level {
62 self->minLogLevel = _level;
65 - (NGLogLevel)logLevel {
66 return self->minLogLevel;
69 - (void)logLevel:(NGLogLevel)_level withFormat:(NSString *)_fmt, ... {
74 if(self->minLogLevel > _level)
78 msg = [[NSString alloc] initWithFormat:_fmt arguments:va];
81 event = [[NGLogEvent alloc] initWithLevel:_level message:msg];
84 // TODO: as soon as we have more appenders, we need to iterate on them
85 [self->_appender appendLogEvent:event];
91 - (BOOL)isLogDebugEnabled {
92 return self->minLogLevel >= NGLogLevelDebug;
95 - (BOOL)isLogInfoEnabled {
96 return self->minLogLevel >= NGLogLevelInfo;
99 - (BOOL)isLogWarnEnabled {
100 return self->minLogLevel >= NGLogLevelWarn;
103 - (BOOL)isLogErrorEnabled {
104 return self->minLogLevel >= NGLogLevelError;
107 - (BOOL)isLogFatalEnabled {
108 return self->minLogLevel >= NGLogLevelFatal;