From 78e1bb7a242c709b0669c49e94cbdf5eb30cc002 Mon Sep 17 00:00:00 2001 From: znek Date: Wed, 17 Nov 2004 16:25:46 +0000 Subject: [PATCH] fixes for NGLogging git-svn-id: http://svn.opengroupware.org/SOPE/trunk@388 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-core/NGExtensions/ChangeLog | 4 ++ .../NGExtensions/NSObject+ExtendedLogging.h | 8 ++-- .../NGExtensions/NGLogging.subproj/ChangeLog | 12 ++++++ .../NGExtensions/NGLogging.subproj/NGLogger.m | 42 ++++++++++--------- .../NSObject+ExtendedLogging.m | 37 +++++++++++++--- sope-core/NGExtensions/Version | 2 +- 6 files changed, 74 insertions(+), 31 deletions(-) diff --git a/sope-core/NGExtensions/ChangeLog b/sope-core/NGExtensions/ChangeLog index d3ac7212..29e08c57 100644 --- a/sope-core/NGExtensions/ChangeLog +++ b/sope-core/NGExtensions/ChangeLog @@ -1,3 +1,7 @@ +2004-11-17 Marcus Mueller + + * NGLogging: updated (v4.5.131) + 2004-11-17 Matthew Joyce * NGBundleManager.m: check whether bundle is nil prior running a type diff --git a/sope-core/NGExtensions/NGExtensions/NSObject+ExtendedLogging.h b/sope-core/NGExtensions/NGExtensions/NSObject+ExtendedLogging.h index e4cd2dab..afdf3dea 100644 --- a/sope-core/NGExtensions/NGExtensions/NSObject+ExtendedLogging.h +++ b/sope-core/NGExtensions/NGExtensions/NSObject+ExtendedLogging.h @@ -26,11 +26,11 @@ typedef enum { NGLogLevelOff = 0, - NGLogLevelDebug = 1, - NGLogLevelInfo = 2, + NGLogLevelFatal = 1, + NGLogLevelError = 2, NGLogLevelWarn = 3, - NGLogLevelError = 4, - NGLogLevelFatal = 5, + NGLogLevelInfo = 4, + NGLogLevelDebug = 5, NGLogLevelAll = 6 } NGLogLevel; diff --git a/sope-core/NGExtensions/NGLogging.subproj/ChangeLog b/sope-core/NGExtensions/NGLogging.subproj/ChangeLog index 3996480a..dfb9ca4e 100644 --- a/sope-core/NGExtensions/NGLogging.subproj/ChangeLog +++ b/sope-core/NGExtensions/NGLogging.subproj/ChangeLog @@ -1,3 +1,15 @@ +2004-11-17 Marcus Mueller + + * NSObject+NGExtendedLogging.h: fixed some serious misordering in + log levels (thanks to Helge Hess for reporting this! ;-) + + * NSObject+NGExtendedLogging.m: some optimizations to default logging + facilities (check wheter loglevel is enabled before allocating + strings which is expensive). + + * NGLogger.m: changed some code to address changes in NGLogLevel, + shortcut logging immediately if minimum log level is not met. + 2004-11-12 Helge Hess * deprecated -defaultManager in favor of -defaultLoggerManager diff --git a/sope-core/NGExtensions/NGLogging.subproj/NGLogger.m b/sope-core/NGExtensions/NGLogging.subproj/NGLogger.m index 0799ac9a..d6abd8e0 100644 --- a/sope-core/NGExtensions/NGLogging.subproj/NGLogger.m +++ b/sope-core/NGExtensions/NGLogging.subproj/NGLogger.m @@ -26,10 +26,14 @@ @implementation NGLogger -static Class StrClass = Nil; +static Class NSStringClass = Nil; + (void)initialize { - StrClass = [NSString class]; + static BOOL didInit = NO; + if(didInit) + return; + didInit = YES; + NSStringClass = [NSString class]; } - (id)init { @@ -63,56 +67,54 @@ static Class StrClass = Nil; - (void)setLogLevel:(NGLogLevel)_level { self->logLevel = _level; } - - (NGLogLevel)logLevel { return self->logLevel; } /* logging */ +- (void)logLevel:(NGLogLevel)_level message:(NSString *)_msg { + NGLogEvent *event; + + if(self->logLevel < _level) + return; + + event = [[NGLogEvent alloc] initWithLevel:_level message:_msg]; + + // iterate appenders + // TODO: as soon as we have more appenders, we need to iterate on them + [self->_appender appendLogEvent:event]; + [event release]; +} + - (void)logLevel:(NGLogLevel)_level withFormat:(NSString *)_fmt, ... { NSString *msg; va_list va; - if(self->logLevel > _level) + if(self->logLevel < _level) return; va_start(va, _fmt); - msg = [[StrClass alloc] initWithFormat:_fmt arguments:va]; + msg = [[NSStringClass alloc] initWithFormat:_fmt arguments:va]; va_end(va); [self logLevel:_level message:msg]; [msg release]; } -- (void)logLevel:(NGLogLevel)_level message:(NSString *)_msg { - NGLogEvent *event; - - event = [[NGLogEvent alloc] initWithLevel:_level message:_msg]; - - // iterate appenders - // TODO: as soon as we have more appenders, we need to iterate on them - [self->_appender appendLogEvent:event]; - [event release]; -} - /* log conditions */ - (BOOL)isLogDebugEnabled { return self->logLevel >= NGLogLevelDebug; } - - (BOOL)isLogInfoEnabled { return self->logLevel >= NGLogLevelInfo; } - - (BOOL)isLogWarnEnabled { return self->logLevel >= NGLogLevelWarn; } - - (BOOL)isLogErrorEnabled { return self->logLevel >= NGLogLevelError; } - - (BOOL)isLogFatalEnabled { return self->logLevel >= NGLogLevelFatal; } diff --git a/sope-core/NGExtensions/NGLogging.subproj/NSObject+ExtendedLogging.m b/sope-core/NGExtensions/NGLogging.subproj/NSObject+ExtendedLogging.m index 0e28bf2d..4551c7e8 100644 --- a/sope-core/NGExtensions/NGLogging.subproj/NSObject+ExtendedLogging.m +++ b/sope-core/NGExtensions/NGLogging.subproj/NSObject+ExtendedLogging.m @@ -44,57 +44,82 @@ /* log methods */ - (void)logDebugWithFormat:(NSString *)_fmt, ... { + NGLogger *logger; NSString *msg; va_list va; + logger = [self logger]; + if(![logger isLogDebugEnabled]) + return; + va_start(va, _fmt); msg = [[NSString alloc] initWithFormat:_fmt arguments:va]; va_end(va); - [self logLevel:NGLogLevelDebug message:msg]; + [logger logLevel:NGLogLevelDebug message:msg]; [msg release]; } - (void)logInfoWithFormat:(NSString *)_fmt, ... { + NGLogger *logger; NSString *msg; va_list va; + logger = [self logger]; + if(![logger isLogInfoEnabled]) + return; + va_start(va, _fmt); msg = [[NSString alloc] initWithFormat:_fmt arguments:va]; va_end(va); - [self logLevel:NGLogLevelInfo message:msg]; + [logger logLevel:NGLogLevelInfo message:msg]; [msg release]; } - (void)logWarnWithFormat:(NSString *)_fmt, ... { + NGLogger *logger; NSString *msg; va_list va; + logger = [self logger]; + if(![logger isLogWarnEnabled]) + return; + va_start(va, _fmt); msg = [[NSString alloc] initWithFormat:_fmt arguments:va]; va_end(va); - [self logLevel:NGLogLevelWarn message:msg]; + [logger logLevel:NGLogLevelWarn message:msg]; [msg release]; } - (void)logErrorWithFormat:(NSString *)_fmt, ... { + NGLogger *logger; NSString *msg; va_list va; + logger = [self logger]; + if(![logger isLogErrorEnabled]) + return; + va_start(va, _fmt); msg = [[NSString alloc] initWithFormat:_fmt arguments:va]; va_end(va); - [self logLevel:NGLogLevelError message:msg]; + [logger logLevel:NGLogLevelError message:msg]; [msg release]; } - (void)logFatalWithFormat:(NSString *)_fmt, ... { + NGLogger *logger; NSString *msg; va_list va; - + + logger = [self logger]; + if(![logger isLogFatalEnabled]) + return; + va_start(va, _fmt); msg = [[NSString alloc] initWithFormat:_fmt arguments:va]; va_end(va); - [self logLevel:NGLogLevelFatal message:msg]; + [logger logLevel:NGLogLevelFatal message:msg]; [msg release]; } diff --git a/sope-core/NGExtensions/Version b/sope-core/NGExtensions/Version index d22cd076..d4cea4ee 100644 --- a/sope-core/NGExtensions/Version +++ b/sope-core/NGExtensions/Version @@ -1,6 +1,6 @@ # version -SUBMINOR_VERSION:=130 +SUBMINOR_VERSION:=131 # v4.3.115 requires libFoundation v1.0.59 # v4.2.72 requires libEOControl v4.2.39 -- 2.39.5