]> err.no Git - sope/blob - sope-core/NGExtensions/NGLogging.subproj/NGLogAppender.m
Add libxml2-dev to libsope-xml4.7-dev deps
[sope] / sope-core / NGExtensions / NGLogging.subproj / NGLogAppender.m
1 /*
2   Copyright (C) 2004-2005 SKYRIX Software AG
3   
4   This file is part of SOPE.
5   
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
9   later version.
10   
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.
15   
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
19   02111-1307, USA.
20 */
21
22 #include "NGLogAppender.h"
23 #include "NGLogLevel.h"
24 #include "NGLogEvent.h"
25 #include "NGLogEventFormatter.h"
26 #include "common.h"
27
28 @implementation NGLogAppender
29
30 static NSString *defaultAppenderClassName = nil;
31
32 + (void)initialize {
33   static BOOL    didInit = NO;
34   NSUserDefaults *ud;
35
36   if (didInit) return;
37   
38   didInit = YES;
39   ud      = [NSUserDefaults standardUserDefaults];
40   defaultAppenderClassName =
41     [[ud stringForKey:@"NGLogDefaultAppenderClass"] retain];
42   if (defaultAppenderClassName == nil)
43     defaultAppenderClassName = @"NGLogStdoutAppender";
44 }
45
46 + (id)logAppenderFromConfig:(NSDictionary *)_config {
47   NSString *className;
48   Class    clazz;
49   id       appender;
50
51   className   = [_config objectForKey:@"Class"];
52   if (!className)
53     className = defaultAppenderClassName;
54   clazz = NSClassFromString(className);
55   if (clazz == Nil) {
56     NSLog(@"ERROR: can't instantiate appender class named '%@'",
57           className);
58     return nil;
59   }
60   appender = [[[clazz alloc] initWithConfig:_config] autorelease];
61   return appender;
62 }
63
64 - (id)initWithConfig:(NSDictionary *)_config {
65   self = [super init];
66   if (self) {
67     NSDictionary *formatterConfig;
68     
69     formatterConfig = [_config objectForKey:@"Formatter"];
70     self->formatter =
71       [[NGLogEventFormatter logEventFormatterFromConfig:formatterConfig]
72                             retain];
73   }
74   return self;
75 }
76
77 - (void)appendLogEvent:(NGLogEvent *)_event {
78 #if LIB_FOUNDATION_LIBRARY
79   [self subclassResponsibility:_cmd];
80 #else
81   NSLog(@"ERROR(%s): method should be implemented by subclass!",
82           __PRETTY_FUNCTION__);
83 #endif
84 }
85
86 /* formatting */
87
88 - (NSString *)formattedEvent:(NGLogEvent *)_event {
89   return [self->formatter formattedEvent:_event];
90 }
91
92 @end /* NGLogAppender */