+2004-11-12 Helge Hess <helge.hess@opengroupware.org>
+
+ * NGLogging: code cleanup (v4.5.128)
+
2004-11-12 Marcus Mueller <znek@mulle-kybernetik.com>
- * GNUmakefile: added NGLogging.subproj (v4.3.127)
+ * GNUmakefile: added NGLogging.subproj (v4.5.127)
2004-10-21 Helge Hess <helge.hess@skyrix.com>
/*
- Copyright (C) 2000-2004 SKYRIX Software AG
+ Copyright (C) 2004 SKYRIX Software AG
This file is part of OpenGroupware.org.
#define __NGExtensions_NGLogAppender_H_
/*
- Abstract superclass for all appenders.
+ Abstract superclass for all log appenders.
*/
-#import <Foundation/Foundation.h>
-#include <NGExtensions/NSObject+ExtendedLogging.h>
+#import <Foundation/NSObject.h>
+#include <NGExtensions/NSObject+ExtendedLogging.h> /* for LogLevel */
@class NGLogEvent;
/*
- Copyright (C) 2000-2004 SKYRIX Software AG
+ Copyright (C) 2004 SKYRIX Software AG
This file is part of OpenGroupware.org.
/*
- Copyright (C) 2000-2004 SKYRIX Software AG
+ Copyright (C) 2004 SKYRIX Software AG
This file is part of OpenGroupware.org.
#ifndef __NGExtensions_NGLogEvent_H_
#define __NGExtensions_NGLogEvent_H_
-#import <Foundation/Foundation.h>
-#include <NGExtensions/NSObject+ExtendedLogging.h>
+#import <Foundation/NSObject.h>
+#import <Foundation/NSDate.h>
+#include <NGExtensions/NSObject+ExtendedLogging.h> /* for NGLogLevel */
+
+@class NSString;
@interface NGLogEvent : NSObject
{
- NSString *msg;
- NGLogLevel level;
+ NSString *msg;
+ NGLogLevel level;
NSTimeInterval date;
}
- (id)initWithLevel:(NGLogLevel)_level message:(NSString *)_msg;
+/* accessors */
+
- (NGLogLevel)level;
- (NSString *)message;
- (NSDate *)date;
#include <NGExtensions/NGLogAppender.h>
+/*
+ NGLogSyslogAppender
+
+ An appender which writes to the systems syslog facility.
+*/
+
+@class NSString;
+
@interface NGLogSyslogAppender : NGLogAppender
{
}
/*
- Copyright (C) 2000-2004 SKYRIX Software AG
+ Copyright (C) 2004 SKYRIX Software AG
This file is part of OpenGroupware.org.
#define __NGExtensions_NGLogger_H_
/*
- The logger, modeled closely after log4j.
- */
+ NGLogger
+
+ A logger class, modeled closely after Log4J.
+
+ TODO: explain more.
+*/
-#import <Foundation/Foundation.h>
+#import <Foundation/NSObject.h>
#include <NGExtensions/NSObject+ExtendedLogging.h>
-
@interface NGLogger : NSObject
{
NGLogLevel logLevel;
- id _appender; // going away as soon as we have a config
+ id _appender; // going away as soon as we have a config
}
- (id)initWithLogLevel:(NGLogLevel)_level;
-- (void)logLevel:(NGLogLevel)_level message:(NSString *)_msg;
-- (void)logLevel:(NGLogLevel)_level withFormat:(NSString *)_fmt, ...;
+/* accessors */
- (void)setLogLevel:(NGLogLevel)_level;
- (NGLogLevel)logLevel;
+/* logging */
+
+- (void)logLevel:(NGLogLevel)_level message:(NSString *)_msg;
+- (void)logLevel:(NGLogLevel)_level withFormat:(NSString *)_fmt, ...;
+
@end
#endif /* __NGExtensions_NGLogger_H_ */
/*
- Copyright (C) 2000-2004 SKYRIX Software AG
+ Copyright (C) 2004 SKYRIX Software AG
This file is part of OpenGroupware.org.
#ifndef __NGExtensions_NGLoggerManager_H_
#define __NGExtensions_NGLoggerManager_H_
-#import <Foundation/Foundation.h>
+#import <Foundation/NSObject.h>
+@class NSString, NSMutableDictionary;
@class NGLogger;
@interface NGLoggerManager : NSObject
NSMutableDictionary *loggerMap;
}
-+ (id)defaultManager;
++ (id)defaultLoggerManager;
+
+/* operations */
- (NGLogger *)loggerForDefaultKey:(NSString *)_defaultKey;
#ifndef __NSObject_ExtendedLogging_H_
#define __NSObject_ExtendedLogging_H_
-#import <Foundation/Foundation.h>
+#import <Foundation/NSObject.h>
typedef enum {
NGLogLevelOff = 0,
NGLogLevelAll = 6
} NGLogLevel;
-@interface NSObject (NGExtendedLogging)
+@interface NSObject(NGExtendedLogging)
- (id)logger;
+/* convenience methods */
+
- (void)logDebugWithFormat:(NSString *)_fmt, ...;
- (void)logInfoWithFormat:(NSString *)_fmt, ...;
- (void)logWarnWithFormat:(NSString *)_fmt, ...;
- (void)logErrorWithFormat:(NSString *)_fmt, ...;
- (void)logFatalWithFormat:(NSString *)_fmt, ...;
+/* conditions (try to avoid these, slow!) */
+
- (BOOL)isLogDebugEnabled;
- (BOOL)isLogInfoEnabled;
- (BOOL)isLogWarnEnabled;
- (BOOL)isLogErrorEnabled;
- (BOOL)isLogFatalEnabled;
+/* generic methods */
+
- (void)logLevel:(NGLogLevel)_level message:(NSString *)_msg;
- (void)logLevel:(NGLogLevel)_level withFormat:(NSString *)_fmt, ...;
+2004-11-12 Helge Hess <helge.hess@opengroupware.org>
+
+ * deprecated -defaultManager in favor of -defaultLoggerManager
+
+ * code cleanups for SOPE styleguides
+
2004-11-12 Marcus Mueller <znek@mulle-kybernetik.com>
* NSObject+ExtendedLogging.[hm]: -(id)logger queries NGLoggerManager
SUBPROJECT_NAME = NGLogging
-NGLogging_OBJC_FILES = \
+NGLogging_OBJC_FILES += \
NGLogger.m \
NGLoggerManager.m \
NGLogEvent.m \
NGLogAppender.m \
NGLogConsoleAppender.m \
- NGLogSyslogAppender.m \
NSObject+ExtendedLogging.m \
+# TODO: disable on Windows
+NGLogging_OBJC_FILES += \
+ NGLogSyslogAppender.m
+
ADDITIONAL_INCLUDE_DIRS += -I. -I../NGExtensions/ -I.. -I../..
-include GNUmakefile.preamble
/*
- Copyright (C) 2000-2004 SKYRIX Software AG
-
- This file is part of OpenGroupware.org.
-
- OGo is free software; you can redistribute it and/or modify it under
- the terms of the GNU Lesser General Public License as published by the
- Free Software Foundation; either version 2, or (at your option) any
- later version.
-
- OGo is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with OGo; see the file COPYING. If not, write to the
- Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
- */
+ Copyright (C) 2004 SKYRIX Software AG
+
+ This file is part of OpenGroupware.org.
+
+ OGo is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with OGo; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
#include "NGLogAppender.h"
#include "NSObject+ExtendedLogging.h"
return name;
}
-@end
+@end /* NGLogAppender */
/*
- Copyright (C) 2000-2004 SKYRIX Software AG
-
- This file is part of OpenGroupware.org.
-
- OGo is free software; you can redistribute it and/or modify it under
- the terms of the GNU Lesser General Public License as published by the
- Free Software Foundation; either version 2, or (at your option) any
- later version.
-
- OGo is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with OGo; see the file COPYING. If not, write to the
- Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
- */
+ Copyright (C) 2000-2004 SKYRIX Software AG
+
+ This file is part of OpenGroupware.org.
+
+ OGo is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with OGo; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
#include "NGLogEvent.h"
#include "common.h"
@implementation NGLogEvent
+static Class DateClass = Nil;
+
++ (void)initialize {
+ DateClass = [NSDate class];
+}
+
- (id)initWithLevel:(NGLogLevel)_level message:(NSString *)_msg {
if((self = [super init])) {
- self->date = [NSDate timeIntervalSinceReferenceDate];
+ self->date = [DateClass timeIntervalSinceReferenceDate];
self->level = _level;
- ASSIGN(self->msg, _msg);
+ self->msg = [_msg copy];
}
return self;
}
[super dealloc];
}
+/* accessors */
+
- (NGLogLevel)level {
return self->level;
}
}
- (NSDate *)date {
- return [NSDate dateWithTimeIntervalSinceReferenceDate:self->date];
+ return [DateClass dateWithTimeIntervalSinceReferenceDate:self->date];
}
-@end
+@end /* NGLogEvent */
/*
- Copyright (C) 2000-2004 SKYRIX Software AG
-
- This file is part of OpenGroupware.org.
-
- OGo is free software; you can redistribute it and/or modify it under
- the terms of the GNU Lesser General Public License as published by the
- Free Software Foundation; either version 2, or (at your option) any
- later version.
-
- OGo is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with OGo; see the file COPYING. If not, write to the
- Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
- */
+ Copyright (C) 2000-2004 SKYRIX Software AG
+
+ This file is part of OpenGroupware.org.
+
+ OGo is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with OGo; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
#include "NGLogSyslogAppender.h"
#include "NGLogEvent.h"
NSUserDefaults *ud;
static BOOL isInitialized = NO;
- if(isInitialized)
+ if (isInitialized)
return;
ud = [NSUserDefaults standardUserDefaults];
+ (id)sharedAppender {
static id sharedAppender = nil;
- if(sharedAppender == nil) {
+ if (sharedAppender == nil) {
sharedAppender = [[self alloc] init];
}
return sharedAppender;
}
- (id)initWithIdentifier:(NSString *)_ident {
- if((self = [super init])) {
-#warning ** default flags?
+ if ((self = [super init])) {
+ // TODO: default flags?
+ // TODO: error code processing?
openlog([_ident cString], LOG_PID | LOG_NDELAY, LOG_USER);
}
return self;
[super dealloc];
}
+/* operations */
+
- (void)appendLogEvent:(NGLogEvent *)_event {
NSString *formattedMsg;
int level;
return level;
}
-@end
+@end /* NGLogSyslogAppender */
/*
- Copyright (C) 2000-2004 SKYRIX Software AG
-
- This file is part of OpenGroupware.org.
-
- OGo is free software; you can redistribute it and/or modify it under
- the terms of the GNU Lesser General Public License as published by the
- Free Software Foundation; either version 2, or (at your option) any
- later version.
-
- OGo is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with OGo; see the file COPYING. If not, write to the
- Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
- */
+ Copyright (C) 2004 SKYRIX Software AG
+
+ This file is part of OpenGroupware.org.
+
+ OGo is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with OGo; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
#include "NGLogger.h"
#include "common.h"
@implementation NGLogger
+static Class StrClass = Nil;
+
++ (void)initialize {
+ StrClass = [NSString class];
+}
+
- (id)init {
- self = [self initWithLogLevel:NGLogLevelAll];
- return self;
+ return [self initWithLogLevel:NGLogLevelAll];
}
- (id)initWithLogLevel:(NGLogLevel)_level {
- if((self = [super init])) {
+ if ((self = [super init])) {
NSUserDefaults *ud;
NSString *appenderClassName;
[self setLogLevel:_level];
-#warning ** remove this as soon as we have a config
+ // TODO: remove this as soon as we have a config
ud = [NSUserDefaults standardUserDefaults];
appenderClassName = [ud stringForKey:@"NGLogDefaultAppenderClass"];
- if(appenderClassName == nil)
+ if (appenderClassName == nil)
appenderClassName = @"NGLogConsoleAppender";
self->_appender = [[NSClassFromString(appenderClassName) alloc] init];
}
[super dealloc];
}
+/* accessors */
- (void)setLogLevel:(NGLogLevel)_level {
self->logLevel = _level;
return self->logLevel;
}
+/* logging */
+
- (void)logLevel:(NGLogLevel)_level withFormat:(NSString *)_fmt, ... {
NSString *msg;
va_list va;
return;
va_start(va, _fmt);
- msg = [[NSString alloc] initWithFormat:_fmt arguments:va];
+ msg = [[StrClass alloc] initWithFormat:_fmt arguments:va];
va_end(va);
[self logLevel:_level message:msg];
[msg release];
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;
}
return self->logLevel >= NGLogLevelFatal;
}
-@end
+@end /* NGLogger */
#include "NGLoggerManager.h"
#include "NSObject+ExtendedLogging.h"
#include "NGLogger.h"
+#include "common.h"
@interface NGLoggerManager (PrivateAPI)
- (NGLogLevel)_logLevelForString:(NSString *)_defaultValue;
+ (void)initialize {
static BOOL didInit = NO;
- if(didInit)
+ if (didInit)
return;
didInit = YES;
sharedInstance = [[self alloc] init];
- sharedNull = [NSNull null];
+ sharedNull = [[NSNull null] retain];
}
-+ (id)defaultManager {
++ (id)defaultLoggerManager {
return sharedInstance;
}
++ (id)defaultManager {
+ NSLog(@"WARNING(%s): called deprecated method.", __PRETTY_FUNCTION__);
+ return [self defaultLoggerManager];
+}
- (id)init {
self = [super init];
- if(self) {
+ if (self) {
self->loggerMap = [[NSMutableDictionary alloc] initWithCapacity:50];
}
return self;
[super dealloc];
}
+/* operations */
+
- (NGLogger *)loggerForDefaultKey:(NSString *)_defaultKey {
id logger;
logger = [self->loggerMap objectForKey:_defaultKey];
- if(!logger) {
+ if (!logger) {
NSUserDefaults *ud;
NSString *levelId;
NGLogLevel level;
ud = [NSUserDefaults standardUserDefaults];
levelId = [[ud stringForKey:_defaultKey] uppercaseString];
level = [self _logLevelForString:levelId];
- if(level == NGLogLevelOff) {
+ if (level == NGLogLevelOff) {
[self->loggerMap setObject:sharedNull forKey:_defaultKey];
logger = sharedNull;
}
/* Private */
- (NGLogLevel)_logLevelForString:(NSString *)_defaultValue {
- if(!_defaultValue || [_defaultValue isEqualToString:@"NO"])
+ if ([_defaultValue length] == 0 || [_defaultValue isEqualToString:@"NO"])
return NGLogLevelOff;
- else if([_defaultValue isEqualToString:@"YES"] ||
+
+ if ([_defaultValue isEqualToString:@"YES"] ||
[_defaultValue isEqualToString:@"DEBUG"])
return NGLogLevelDebug;
- else if([_defaultValue isEqualToString:@"INFO"])
+
+ if ([_defaultValue isEqualToString:@"INFO"])
return NGLogLevelInfo;
- else if([_defaultValue isEqualToString:@"WARN"])
+ if ([_defaultValue isEqualToString:@"WARN"])
return NGLogLevelWarn;
- else if([_defaultValue isEqualToString:@"ERROR"])
+ if ([_defaultValue isEqualToString:@"ERROR"])
return NGLogLevelError;
- else if([_defaultValue isEqualToString:@"FATAL"])
+ if ([_defaultValue isEqualToString:@"FATAL"])
return NGLogLevelFatal;
+
return NGLogLevelAll;
}
-@end
+@end /* NGLoggerManager */
/*
- Copyright (C) 2000-2004 SKYRIX Software AG
-
- This file is part of OpenGroupware.org.
-
- OGo is free software; you can redistribute it and/or modify it under
- the terms of the GNU Lesser General Public License as published by the
- Free Software Foundation; either version 2, or (at your option) any
- later version.
-
- OGo is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with OGo; see the file COPYING. If not, write to the
- Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
- */
+ Copyright (C) 2004 SKYRIX Software AG
+
+ This file is part of OpenGroupware.org.
+
+ OGo is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with OGo; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
#include "NSObject+ExtendedLogging.h"
#include "NGLogger.h"
#include "NGLoggerManager.h"
+#include "common.h"
-@implementation NSObject (NGExtendedLogging)
+@implementation NSObject(NGExtendedLogging)
- (id)logger {
static id sharedLogger = nil;
static BOOL shouldLog = YES;
- if(sharedLogger == nil && shouldLog) {
+
+ if (sharedLogger == nil && shouldLog) {
NGLoggerManager *lm;
- lm = [NGLoggerManager defaultManager];
+
+ lm = [NGLoggerManager defaultLoggerManager];
sharedLogger = [lm loggerForDefaultKey:@"NGDefaultLogLevel"];
- if(!sharedLogger)
+ if (!sharedLogger)
shouldLog = NO;
}
return sharedLogger;
}
+/* log methods */
+
- (void)logDebugWithFormat:(NSString *)_fmt, ... {
NSString *msg;
va_list va;
[msg release];
}
+/* log conditions (do not use, slow ...) */
+
- (BOOL)isLogDebugEnabled {
return [[self logger] isLogDebugEnabled];
}
return [[self logger] isLogFatalEnabled];
}
-@end
+@end /* NSObject(NGExtendedLogging) */
# version
-SUBMINOR_VERSION:=127
+SUBMINOR_VERSION:=128
# v4.3.115 requires libFoundation v1.0.59
# v4.2.72 requires libEOControl v4.2.39