2 Copyright (C) 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
29 static Class StrClass = Nil;
32 StrClass = [NSString class];
36 return [self initWithLogLevel:NGLogLevelAll];
39 - (id)initWithLogLevel:(NGLogLevel)_level {
40 if ((self = [super init])) {
42 NSString *appenderClassName;
44 [self setLogLevel:_level];
46 // TODO: remove this as soon as we have a config
47 ud = [NSUserDefaults standardUserDefaults];
48 appenderClassName = [ud stringForKey:@"NGLogDefaultAppenderClass"];
49 if (appenderClassName == nil)
50 appenderClassName = @"NGLogConsoleAppender";
51 self->_appender = [[NSClassFromString(appenderClassName) alloc] init];
57 [self->_appender release];
63 - (void)setLogLevel:(NGLogLevel)_level {
64 self->logLevel = _level;
67 - (NGLogLevel)logLevel {
68 return self->logLevel;
73 - (void)logLevel:(NGLogLevel)_level withFormat:(NSString *)_fmt, ... {
77 if(self->logLevel > _level)
81 msg = [[StrClass alloc] initWithFormat:_fmt arguments:va];
83 [self logLevel:_level message:msg];
87 - (void)logLevel:(NGLogLevel)_level message:(NSString *)_msg {
90 event = [[NGLogEvent alloc] initWithLevel:_level message:_msg];
93 // TODO: as soon as we have more appenders, we need to iterate on them
94 [self->_appender appendLogEvent:event];
100 - (BOOL)isLogDebugEnabled {
101 return self->logLevel >= NGLogLevelDebug;
104 - (BOOL)isLogInfoEnabled {
105 return self->logLevel >= NGLogLevelInfo;
108 - (BOOL)isLogWarnEnabled {
109 return self->logLevel >= NGLogLevelWarn;
112 - (BOOL)isLogErrorEnabled {
113 return self->logLevel >= NGLogLevelError;
116 - (BOOL)isLogFatalEnabled {
117 return self->logLevel >= NGLogLevelFatal;