]> err.no Git - scalable-opengroupware.org/blob - WebUI/NGExtensions/NGLogging/NGLogger.m
9f9d4853dd346edc4b57083e3993b9569341a662
[scalable-opengroupware.org] / 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 #include "NGLogConsoleAppender.h"
30
31
32 @implementation NGLogger
33
34 - (id)init {
35     self = [self initWithLogLevel:NGLogLevelAll];
36     return self;
37 }
38
39 - (id)initWithLogLevel:(NGLogLevel)_level {
40     if((self = [super init])) {
41         [self setLogLevel:_level];
42 #warning ** remove this as soon as we have a config
43         self->_appender = [[NGLogConsoleAppender alloc] init];
44     }
45     return self;
46 }
47
48 - (void)dealloc {
49     [self->_appender release];
50     [super dealloc];
51 }
52
53
54 - (void)setLogLevel:(NGLogLevel)_level {
55     self->minLogLevel = _level;
56 }
57
58 - (NGLogLevel)logLevel {
59     return self->minLogLevel;
60 }
61
62 - (void)logLevel:(NGLogLevel)_level withFormat:(NSString *)_fmt, ... {
63     NSString *msg;
64     NGLogEvent *event;
65     va_list va;
66
67     if(self->minLogLevel > _level)
68         return;
69
70     va_start(va, _fmt);
71     msg = [[NSString alloc] initWithFormat:_fmt arguments:va];
72     va_end(va);
73
74     event = [[NGLogEvent alloc] initWithLevel:_level message:msg];
75
76     // iterate appenders
77     // TODO: as soon as we have more appenders, we need to iterate on them
78     [self->_appender appendLogEvent:event];
79
80     [event release];
81     [msg release];
82 }
83
84 - (BOOL)isLogDebugEnabled {
85     return self->minLogLevel >= NGLogLevelDebug;
86 }
87
88 - (BOOL)isLogInfoEnabled {
89     return self->minLogLevel >= NGLogLevelInfo;
90 }
91
92 - (BOOL)isLogWarnEnabled {
93     return self->minLogLevel >= NGLogLevelWarn;
94 }
95
96 - (BOOL)isLogErrorEnabled {
97     return self->minLogLevel >= NGLogLevelError;
98 }
99
100 - (BOOL)isLogFatalEnabled {
101     return self->minLogLevel >= NGLogLevelFatal;
102 }
103
104 @end