]> err.no Git - scalable-opengroupware.org/blob - Misc/WebUI/NGExtensions/NGLogging/NGLogger.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1004 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / Misc / WebUI / NGExtensions / NGLogging / NGLogger.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OGo
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23
24 #include "NGLogger.h"
25 #include <NGExtensions/NGExtensions.h>
26 #include "common.h"
27 #include "NGLogEvent.h"
28 #include "NGLogAppender.h"
29
30
31 @implementation NGLogger
32
33 - (id)init {
34     self = [self initWithLogLevel:NGLogLevelAll];
35     return self;
36 }
37
38 - (id)initWithLogLevel:(NGLogLevel)_level {
39     if((self = [super init])) {
40         NSUserDefaults *ud;
41         NSString *appenderClassName;
42
43         [self setLogLevel:_level];
44
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];
51     }
52     return self;
53 }
54
55 - (void)dealloc {
56     [self->_appender release];
57     [super dealloc];
58 }
59
60
61 - (void)setLogLevel:(NGLogLevel)_level {
62     self->minLogLevel = _level;
63 }
64
65 - (NGLogLevel)logLevel {
66     return self->minLogLevel;
67 }
68
69 - (void)logLevel:(NGLogLevel)_level withFormat:(NSString *)_fmt, ... {
70     NSString *msg;
71     NGLogEvent *event;
72     va_list va;
73
74     if(self->minLogLevel > _level)
75         return;
76
77     va_start(va, _fmt);
78     msg = [[NSString alloc] initWithFormat:_fmt arguments:va];
79     va_end(va);
80
81     event = [[NGLogEvent alloc] initWithLevel:_level message:msg];
82
83     // iterate appenders
84     // TODO: as soon as we have more appenders, we need to iterate on them
85     [self->_appender appendLogEvent:event];
86
87     [event release];
88     [msg release];
89 }
90
91 - (BOOL)isLogDebugEnabled {
92     return self->minLogLevel >= NGLogLevelDebug;
93 }
94
95 - (BOOL)isLogInfoEnabled {
96     return self->minLogLevel >= NGLogLevelInfo;
97 }
98
99 - (BOOL)isLogWarnEnabled {
100     return self->minLogLevel >= NGLogLevelWarn;
101 }
102
103 - (BOOL)isLogErrorEnabled {
104     return self->minLogLevel >= NGLogLevelError;
105 }
106
107 - (BOOL)isLogFatalEnabled {
108     return self->minLogLevel >= NGLogLevelFatal;
109 }
110
111 @end