2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
24 #include "NGLogEvent.h"
25 #include "NGLogAppender.h"
27 @implementation NGLogger
30 self = [self initWithLogLevel:NGLogLevelAll];
34 - (id)initWithLogLevel:(NGLogLevel)_level {
35 if((self = [super init])) {
37 NSString *appenderClassName;
39 [self setLogLevel:_level];
41 #warning ** remove this as soon as we have a config
42 ud = [NSUserDefaults standardUserDefaults];
43 appenderClassName = [ud stringForKey:@"NGLogDefaultAppenderClass"];
44 if(appenderClassName == nil)
45 appenderClassName = @"NGLogConsoleAppender";
46 self->_appender = [[NSClassFromString(appenderClassName) alloc] init];
52 [self->_appender release];
57 - (void)setLogLevel:(NGLogLevel)_level {
58 self->logLevel = _level;
61 - (NGLogLevel)logLevel {
62 return self->logLevel;
65 - (void)logLevel:(NGLogLevel)_level withFormat:(NSString *)_fmt, ... {
69 if(self->logLevel > _level)
73 msg = [[NSString alloc] initWithFormat:_fmt arguments:va];
75 [self logLevel:_level message:msg];
79 - (void)logLevel:(NGLogLevel)_level message:(NSString *)_msg {
82 event = [[NGLogEvent alloc] initWithLevel:_level message:_msg];
85 // TODO: as soon as we have more appenders, we need to iterate on them
86 [self->_appender appendLogEvent:event];
90 - (BOOL)isLogDebugEnabled {
91 return self->logLevel >= NGLogLevelDebug;
94 - (BOOL)isLogInfoEnabled {
95 return self->logLevel >= NGLogLevelInfo;
98 - (BOOL)isLogWarnEnabled {
99 return self->logLevel >= NGLogLevelWarn;
102 - (BOOL)isLogErrorEnabled {
103 return self->logLevel >= NGLogLevelError;
106 - (BOOL)isLogFatalEnabled {
107 return self->logLevel >= NGLogLevelFatal;