+2004-11-19 Helge Hess <helge.hess@opengroupware.org>
+
+ * v4.5.135
+
+ * FdExt.subproj/NSObject+Logs.m: fixed a bug in default logger creation
+ (incorrect static variable)
+
+ * NGLogging: fixed bug in console appender, increased speed, avoid
+ different logger objects for each class
+
2004-11-18 Marcus Mueller <znek@mulle-kybernetik.com>
* v4.5.134
if (logger == nil) {
NGLoggerManager *lm;
- // TODO: broken. If [self class] is passed in, 'logger' can't be a static
- lm = [NGLoggerManager defaultLoggerManager];
+ lm = [NGLoggerManager defaultLoggerManager];
+
+#if 0 // broken: if [self class] is passed in, 'logger' can't be a static
logger = [lm loggerForClass:[self class]];
+#else
+ logger = [lm loggerForClass:[NSObject class]];
+#endif
}
return logger;
}
id _appender; // going away as soon as we have a config
}
++ (id)defaultLogger;
- (id)initWithLogLevel:(NGLogLevel)_level;
/* accessors */
+2004-11-19 Helge Hess <helge.hess@opengroupware.org>
+
+ * NGLoggerManager.m: use default logger if none is registered
+
+ * NGLogger.m: cleaned up -init, added default logger
+
+ * NGLogConsoleAppender.m: removed the bug with using a message in
+ place of a format, rewrote logger to be sufficiently fast
+
2004-11-18 Marcus Mueller <znek@mulle-kybernetik.com>
* NGLogLevel.h: new header bearing the log levels
- (NSString *)formattedEvent:(NGLogEvent *)_event {
NSMutableString *fe;
NSString *lvl;
-
+
lvl = [self localizedNameOfLogLevel:[_event level]];
fe = [NSMutableString stringWithCapacity:128];
if (lvl != nil) {
#include "NGLogConsoleAppender.h"
#include "NGLogEvent.h"
+#include "common.h"
+#include <sys/types.h>
+#include <unistd.h>
@implementation NGLogConsoleAppender
+static Class NSCalendarDateClass = Nil;
+static Class NSProcessInfoClass = Nil;
+static unsigned char *processName = NULL;
+
+static char *monthNames[14] = {
+ "Dec",
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
+ "Jan"
+};
+
++ (void)initialize {
+ if (NSCalendarDateClass == Nil)
+ NSCalendarDateClass = [NSCalendarDate class];
+ if (NSProcessInfoClass == Nil)
+ NSProcessInfoClass = [NSProcessInfo class];
+
+ if (processName == NULL) {
+ /* process name can't change, right? */
+ unsigned len;
+ NSString *pn;
+
+ pn = [[NSProcessInfoClass processInfo] processName];
+ len = [pn cStringLength];
+
+ processName = malloc(len + 4);
+ [pn getCString:processName];
+ }
+}
+
+static __inline__ unsigned char * levelPrefixForEvent(NGLogEvent *_event) {
+ switch ([_event level]) {
+ case NGLogLevelWarn: return "[WARN]";
+ case NGLogLevelError: return "[ERROR]";
+ case NGLogLevelFatal: return "[FATAL]";
+ default: return "";
+ }
+}
+
- (void)appendLogEvent:(NGLogEvent *)_event {
- // TODO: broken, NSLog takes a format string
- NSLog([self formattedEvent:_event]);
+ /* Note: pid can change after a fork() */
+ NSCalendarDate *date;
+
+ // TODO: get time using libc function, cheaper
+ // TODO: set to GMT?
+ date = [[NSCalendarDateClass alloc] init];
+
+ // TODO: cString for message is expensive
+ fprintf(stderr,
+ "%s %02i %02i:%02i:%02i %s [%d]: %s\n",
+ monthNames[[date monthOfYear]],
+ [date dayOfMonth],
+ [date hourOfDay], [date minuteOfHour], [date secondOfMinute],
+ processName,
+ getpid(),
+ [[_event message] cString]);
+
+ [date release];
}
@end /* NGLogConsoleAppender */
NSStringClass = [NSString class];
}
++ (id)defaultLogger {
+ static NGLogger *logger = nil; // THREAD
+
+ if (logger == nil)
+ logger = [[self alloc] init];
+ return logger;
+}
+
- (id)init {
return [self initWithLogLevel:NGLogLevelAll];
}
-- (id)initWithLogLevel:(NGLogLevel)_level {
- self = [super init];
- if (self) {
- NSUserDefaults *ud;
- NSString *appenderClassName;
-
+- (id)initWithLogLevel:(NGLogLevel)_level appender:(id)_appenderParam {
+ if ((self = [super init]) != nil) {
[self setLogLevel:_level];
-
- // TODO: remove this as soon as we have a config
- ud = [NSUserDefaults standardUserDefaults];
- appenderClassName = [ud stringForKey:@"NGLogDefaultAppenderClass"];
- if (appenderClassName == nil)
- appenderClassName = @"NGLogConsoleAppender";
- self->_appender = [[NSClassFromString(appenderClassName) alloc] init];
+ self->_appender = [_appenderParam retain]; // TODO: fix ivar name
}
return self;
}
+- (id)initWithLogLevel:(NGLogLevel)_level {
+ NSUserDefaults *ud;
+ NSString *appenderClassName;
+ id appender;
+
+ // TODO: remove this as soon as we have a config
+ ud = [NSUserDefaults standardUserDefaults];
+ appenderClassName = [ud stringForKey:@"NGLogDefaultAppenderClass"];
+ if (appenderClassName == nil)
+ appenderClassName = @"NGLogConsoleAppender";
+
+ appender = [[NSClassFromString(appenderClassName) alloc] init];
+
+ self = [self initWithLogLevel:_level appender:appender];
+ [appender release];
+ return self;
+}
+
- (void)dealloc {
[self->_appender release];
[super dealloc];
- (NGLogger *)loggerForFacilityNamed:(NSString *)_name {
id logger;
- logger = [self->loggerMap objectForKey:_name];
- if (!logger) {
- logger = [[NGLogger alloc] init];
- [self->loggerMap setObject:logger forKey:_name];
- [logger release];
- }
+ // TODO: expensive, use a faster map (at least NSMapTable)
+ if ((logger = [self->loggerMap objectForKey:_name]) != nil)
+ return logger;
+
+ // TODO: is a registration really faster? I guess not?
+ logger = [NGLogger defaultLogger]; /* fallback to shared logger */
+ [self->loggerMap setObject:logger forKey:_name];
return logger;
}
- (NGLogger *)loggerForClass:(Class)_clazz {
NSString *name;
- name = NSStringFromClass(_clazz);
+ name = _clazz != Nil ? NSStringFromClass(_clazz) : nil;
return [self loggerForFacilityNamed:name];
}
# version
-SUBMINOR_VERSION:=134
+SUBMINOR_VERSION:=135
# v4.3.115 requires libFoundation v1.0.59
# v4.2.72 requires libEOControl v4.2.39