]> err.no Git - sope/blob - sope-core/NGExtensions/FdExt.subproj/NSObject+Logs.m
fixed resource lookup in SoProductResourceManager, added debug logs
[sope] / sope-core / NGExtensions / FdExt.subproj / NSObject+Logs.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
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
22 #include "NSObject+Logs.h"
23 #include "common.h"
24
25 @implementation NSObject(NGLogs)
26
27 static Class StringClass = Nil;
28
29 static inline Class NSStringClass(void) {
30   if (StringClass == Nil) StringClass = [NSString class];
31   return StringClass;
32 }
33
34 - (BOOL)isDebuggingEnabled {
35 #if DEBUG
36   return YES;
37 #else
38   return NO;
39 #endif
40 }
41 - (NSString *)loggingPrefix {
42   /* improve perf ... */
43   return [NSStringClass() stringWithFormat:@"<0x%08X[%@]>",
44                        self, NSStringFromClass([self class])];
45 }
46
47 - (void)logWithFormat:(NSString *)_format arguments:(va_list)ap {
48   NSString *value = nil;
49   
50   value = [[NSStringClass() alloc] initWithFormat:_format arguments:ap];
51   NSLog(@"%@ %@", [self loggingPrefix], value);
52   [value release];
53 }
54
55 - (void)debugWithFormat:(NSString *)_format arguments:(va_list)ap {
56 #if DEBUG
57   NSString *value = nil;
58   
59   if (![self isDebuggingEnabled]) return;
60   
61   value = [[NSStringClass() alloc] initWithFormat:_format arguments:ap];
62   NSLog(@"<%@>D %@", [self loggingPrefix], value);
63   [value release];
64 #else
65 #  warning debug is disabled, debugWithFormat wont print anything ..
66 #endif
67 }
68
69 - (void)logWithFormat:(NSString *)_format, ... {
70   va_list ap;
71   
72   va_start(ap, _format);
73   [self logWithFormat:_format arguments:ap];
74   va_end(ap);
75 }
76 - (void)debugWithFormat:(NSString *)_format, ... {
77   va_list ap;
78   
79   va_start(ap, _format);
80   [self debugWithFormat:_format arguments:ap];
81   va_end(ap);
82 }
83
84 @end /* NSObject(NGLogs) */