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
22 #include "NSObject+Logs.h"
23 #include "NGLoggerManager.h"
27 @implementation NSObject(NGLogs)
29 static Class StringClass = Nil;
31 static inline Class NSStringClass(void) {
32 if (StringClass == Nil) StringClass = [NSString class];
36 - (BOOL)isDebuggingEnabled {
45 static id logger = nil;
50 lm = [NGLoggerManager defaultLoggerManager];
51 logger = [lm loggerForClass:[self class]];
60 - (NSString *)loggingPrefix {
61 /* improve perf ... */
62 return [NSStringClass() stringWithFormat:@"<0x%08X[%@]>",
63 self, NSStringFromClass([self class])];
67 - (void)debugWithFormat:(NSString *)_fmt arguments:(va_list)_va {
71 if (![self isDebuggingEnabled]) return;
73 msg = [[NSStringClass() alloc] initWithFormat:_fmt arguments:_va];
74 [[self debugLogger] debugWithFormat:@"<%@>D %@", [self loggingPrefix], msg];
77 # warning debug is disabled, debugWithFormat wont print anything ..
81 - (void)logWithFormat:(NSString *)_fmt arguments:(va_list)_va {
85 logger = [self logger];
86 if (![logger isLogInfoEnabled]) return;
88 msg = [[NSStringClass() alloc] initWithFormat:_fmt arguments:_va];
89 [logger logWithFormat:@"%@ %@", [self loggingPrefix], msg];
93 - (void)warnWithFormat:(NSString *)_fmt arguments:(va_list)_va {
97 logger = [self logger];
98 if (![logger isLogWarnEnabled]) return;
100 msg = [[NSStringClass() alloc] initWithFormat:_fmt arguments:_va];
101 [logger warnWithFormat:@"%@ %@", [self loggingPrefix], msg];
105 - (void)errorWithFormat:(NSString *)_fmt arguments:(va_list)_va {
109 logger = [self logger];
110 if (![logger isLogErrorEnabled]) return;
112 msg = [[NSStringClass() alloc] initWithFormat:_fmt arguments:_va];
113 [logger errorWithFormat:@"%@ %@", [self loggingPrefix], msg];
117 - (void)fatalWithFormat:(NSString *)_fmt arguments:(va_list)_va {
121 logger = [self logger];
122 if (![logger isLogFatalEnabled]) return;
124 msg = [[NSStringClass() alloc] initWithFormat:_fmt arguments:_va];
125 [logger fatalWithFormat:@"%@ %@", [self loggingPrefix], msg];
129 - (void)debugWithFormat:(NSString *)_fmt, ... {
133 [self debugWithFormat:_fmt arguments:ap];
136 - (void)logWithFormat:(NSString *)_fmt, ... {
140 [self logWithFormat:_fmt arguments:ap];
143 - (void)warnWithFormat:(NSString *)_fmt, ... {
147 [self warnWithFormat:_fmt arguments:ap];
150 - (void)errorWithFormat:(NSString *)_fmt, ... {
154 [self errorWithFormat:_fmt arguments:ap];
157 - (void)fatalWithFormat:(NSString *)_fmt, ... {
161 [self fatalWithFormat:_fmt arguments:ap];
165 @end /* NSObject(NGLogs) */