2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; 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 NSMapTable *loggerForClassMap = NULL;
46 static NGLoggerManager *lm = nil;
49 if (!loggerForClassMap) {
50 loggerForClassMap = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks,
51 NSNonRetainedObjectMapValueCallBacks,
53 lm = [NGLoggerManager defaultLoggerManager];
55 logger = NSMapGet(loggerForClassMap, self->isa);
57 logger = [lm loggerForClass:self->isa];
58 NSMapInsert(loggerForClassMap, self->isa, logger);
68 - (NSString *)loggingPrefix {
69 /* improve perf ... */
70 return [NSStringClass() stringWithFormat:@"<0x%p[%@]>",
71 self, NSStringFromClass([self class])];
75 - (void)debugWithFormat:(NSString *)_fmt arguments:(va_list)_va {
79 if (![self isDebuggingEnabled]) return;
81 msg = [[NSStringClass() alloc] initWithFormat:_fmt arguments:_va];
82 msg2 = [[NSStringClass() alloc] initWithFormat:
83 @"<%@>D %@", [self loggingPrefix], msg];
84 [[self debugLogger] logLevel:NGLogLevelDebug message:msg2];
88 # warning debug is disabled, debugWithFormat wont print anything ..
92 - (void)logWithFormat:(NSString *)_fmt arguments:(va_list)_va {
96 logger = [self logger];
97 if (![logger isLogInfoEnabled]) return;
99 msg = [[NSStringClass() alloc] initWithFormat:_fmt arguments:_va];
100 [logger logWithFormat:@"%@ %@", [self loggingPrefix], msg];
104 - (void)warnWithFormat:(NSString *)_fmt arguments:(va_list)_va {
108 logger = [self logger];
109 if (![logger isLogWarnEnabled]) return;
111 msg = [[NSStringClass() alloc] initWithFormat:_fmt arguments:_va];
112 [logger warnWithFormat:@"%@ %@", [self loggingPrefix], msg];
116 - (void)errorWithFormat:(NSString *)_fmt arguments:(va_list)_va {
120 logger = [self logger];
121 if (![logger isLogErrorEnabled]) return;
123 msg = [[NSStringClass() alloc] initWithFormat:_fmt arguments:_va];
124 [logger errorWithFormat:@"%@ %@", [self loggingPrefix], msg];
128 - (void)fatalWithFormat:(NSString *)_fmt arguments:(va_list)_va {
132 logger = [self logger];
133 if (![logger isLogFatalEnabled]) return;
135 msg = [[NSStringClass() alloc] initWithFormat:_fmt arguments:_va];
136 [logger fatalWithFormat:@"%@ %@", [self loggingPrefix], msg];
140 - (void)debugWithFormat:(NSString *)_fmt, ... {
144 [self debugWithFormat:_fmt arguments:ap];
147 - (void)logWithFormat:(NSString *)_fmt, ... {
151 [self logWithFormat:_fmt arguments:ap];
154 - (void)warnWithFormat:(NSString *)_fmt, ... {
158 [self warnWithFormat:_fmt arguments:ap];
161 - (void)errorWithFormat:(NSString *)_fmt, ... {
165 [self errorWithFormat:_fmt arguments:ap];
168 - (void)fatalWithFormat:(NSString *)_fmt, ... {
172 [self fatalWithFormat:_fmt arguments:ap];
176 @end /* NSObject(NGLogs) */