+2004-05-27 Marcus Mueller <mm@skyrix.com>
+
+ * README: updated
+
2004-05-27 Marcus Mueller <mm@skyrix.com>
* README, NOTES: updated
+2004-05-27 Marcus Mueller <mm@skyrix.com>
+
+ * NGLogAppender.[hm]: introduced -formattedEvent:, currently not
+ configurable.
+
+ * NGLogSyslogAppender.m: works as expected now.
+
+ * NGLogger.m: uses new default (see README) to select the default
+ appender. Not optimal, but sufficient.
+
+ * NGLogConsoleAppender.m: changed to use -formattedEvent: now.
+
2004-05-27 Marcus Mueller <mm@skyrix.com>
* NGLogSyslogAppender.[hm]: syslog appender, untested.
/* subclass responsibility */
- (void)appendLogEvent:(NGLogEvent *)_event;
+- (NSString *)formattedEvent:(NGLogEvent *)_event;
- (NSString *)localizedNameOfLogLevel:(NGLogLevel)_level;
#import "NGLogAppender.h"
+#import "NGLogEvent.h"
@implementation NGLogAppender
[self subclassResponsibility:_cmd];
}
+- (NSString *)formattedEvent:(NGLogEvent *)_event {
+ return [NSString stringWithFormat:@"[%@] %@",
+ [self localizedNameOfLogLevel:[_event level]],
+ [_event message]];
+}
+
- (NSString *)localizedNameOfLogLevel:(NGLogLevel)_level {
NSString *name;
@implementation NGLogConsoleAppender
- (void)appendLogEvent:(NGLogEvent *)_event {
- NSLog(@"%@: %@", [self localizedNameOfLogLevel:[_event level]], [_event message]);
+ NSLog([self formattedEvent:_event]);
}
@end
@interface NGLogSyslogAppender (PrivateAPI)
-- (int)syslogPriorityForLogLevel:(NGLogLevel)_level;
+- (int)syslogLevelForLogLevel:(NGLogLevel)_level;
@end
@implementation NGLogSyslogAppender
}
- (void)appendLogEvent:(NGLogEvent *)_event {
+ NSString *formattedMsg;
int level;
-
- level = [self syslogPriorityForLogLevel:[_event level]];
- syslog(level, [[_event message] cString]);
+
+ formattedMsg = [self formattedEvent:_event];
+ level = [self syslogLevelForLogLevel:[_event level]];
+ syslog(level, [formattedMsg cString]);
}
- (int)syslogLevelForLogLevel:(NGLogLevel)_level {
#include "common.h"
#include "NGLogEvent.h"
#include "NGLogAppender.h"
-#include "NGLogConsoleAppender.h"
@implementation NGLogger
- (id)initWithLogLevel:(NGLogLevel)_level {
if((self = [super init])) {
+ NSUserDefaults *ud;
+ NSString *appenderClassName;
+
[self setLogLevel:_level];
+
#warning ** remove this as soon as we have a config
- self->_appender = [[NGLogConsoleAppender alloc] init];
+ ud = [NSUserDefaults standardUserDefaults];
+ appenderClassName = [ud stringForKey:@"NGLogDefaultAppenderClass"];
+ if(appenderClassName == nil)
+ appenderClassName = @"NGLogConsoleAppender";
+ self->_appender = [[NSClassFromString(appenderClassName) alloc] init];
}
return self;
}
a config for that purpose. Logging is low priority, so we don't need to
do that too soon.
- Syslog appender might be useful for the ministry. Syslog provides its own
- buffering, so syslog appender should be straight forward.
\ No newline at end of file
+ buffering, so syslog appender should be straight forward. Current
+ implementation makes some fix assumptions (log facility).
\ No newline at end of file
UserDefaults
============
- Default | Type | Example Value
- =============================================================
- NGLogSyslogIdentifier | String | WebUI
-
+ Default | Type | Example Value
+ ==============================================================
+ NGLogSyslogIdentifier | String | WebUI
+ NGLogDefaultAppenderClass| String | NGLogConsoleAppender