From a474c863ec9bf27ada8730afe5e6c21533ae3b3e Mon Sep 17 00:00:00 2001 From: znek Date: Fri, 12 Nov 2004 16:20:23 +0000 Subject: [PATCH] New subproject NGLogging added git-svn-id: http://svn.opengroupware.org/SOPE/trunk@363 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-core/NGExtensions/ChangeLog | 4 + sope-core/NGExtensions/GNUmakefile | 21 +- .../NGExtensions.xcode/project.pbxproj | 361 ++++++++++++++++++ .../NGExtensions/NGLogging.subproj/ChangeLog | 30 ++ .../NGLogging.subproj/GNUmakefile | 21 + .../NGLogging.subproj/NGLogAppender.m | 64 ++++ .../NGLogging.subproj/NGLogConsoleAppender.m | 31 ++ .../NGLogging.subproj/NGLogEvent.m | 53 +++ .../NGLogging.subproj/NGLogSyslogAppender.m | 109 ++++++ .../NGExtensions/NGLogging.subproj/NGLogger.m | 110 ++++++ .../NGLogging.subproj/NGLoggerManager.m | 107 ++++++ .../NSObject+ExtendedLogging.m | 131 +++++++ .../NGExtensions/NGLogging.subproj/README | 31 ++ sope-core/NGExtensions/Version | 2 +- 14 files changed, 1070 insertions(+), 5 deletions(-) create mode 100644 sope-core/NGExtensions/NGLogging.subproj/ChangeLog create mode 100644 sope-core/NGExtensions/NGLogging.subproj/GNUmakefile create mode 100644 sope-core/NGExtensions/NGLogging.subproj/NGLogAppender.m create mode 100644 sope-core/NGExtensions/NGLogging.subproj/NGLogConsoleAppender.m create mode 100644 sope-core/NGExtensions/NGLogging.subproj/NGLogEvent.m create mode 100644 sope-core/NGExtensions/NGLogging.subproj/NGLogSyslogAppender.m create mode 100644 sope-core/NGExtensions/NGLogging.subproj/NGLogger.m create mode 100644 sope-core/NGExtensions/NGLogging.subproj/NGLoggerManager.m create mode 100644 sope-core/NGExtensions/NGLogging.subproj/NSObject+ExtendedLogging.m create mode 100644 sope-core/NGExtensions/NGLogging.subproj/README diff --git a/sope-core/NGExtensions/ChangeLog b/sope-core/NGExtensions/ChangeLog index 5fd2ecf0..3fa31299 100644 --- a/sope-core/NGExtensions/ChangeLog +++ b/sope-core/NGExtensions/ChangeLog @@ -1,3 +1,7 @@ +2004-11-12 Marcus Mueller + + * GNUmakefile: added NGLogging.subproj (v4.3.127) + 2004-10-21 Helge Hess * FdExt.subproj/NSString+URLEscaping.m: removed '&' as an URL safe diff --git a/sope-core/NGExtensions/GNUmakefile b/sope-core/NGExtensions/GNUmakefile index 177a82a7..f867f745 100644 --- a/sope-core/NGExtensions/GNUmakefile +++ b/sope-core/NGExtensions/GNUmakefile @@ -65,6 +65,7 @@ libNGExtensions_SUBPROJECTS = \ EOExt.subproj \ XmlExt.subproj \ NGRuleEngine.subproj \ + NGLogging.subproj \ EOExt_HEADER_FILES = \ EOCacheDataSource.h \ @@ -119,11 +120,23 @@ NGRuleEngine_HEADER_FILES = \ NGRuleContext.h \ NGRuleModel.h \ +NGLogging_HEADER_FILES = \ + NGLogging.h \ + NGLogger.h \ + NGLoggerManager.h \ + NGLogEvent.h \ + NGLogAppender.h \ + NGLogConsoleAppender.h \ + NGLogSyslogAppender.h \ + NSObject+ExtendedLogging.h \ + + libNGExtensions_HEADER_FILES += \ - $(FdExt_HEADER_FILES) \ - $(EOExt_HEADER_FILES) \ - $(XmlExt_HEADER_FILES) \ - $(NGRuleEngine_HEADER_FILES) + $(FdExt_HEADER_FILES) \ + $(EOExt_HEADER_FILES) \ + $(XmlExt_HEADER_FILES) \ + $(NGRuleEngine_HEADER_FILES) \ + $(NGLogging_HEADER_FILES) ADDITIONAL_INCLUDE_DIRS += \ -I./NGExtensions/ \ diff --git a/sope-core/NGExtensions/NGExtensions.xcode/project.pbxproj b/sope-core/NGExtensions/NGExtensions.xcode/project.pbxproj index 6dc986f5..518a70db 100644 --- a/sope-core/NGExtensions/NGExtensions.xcode/project.pbxproj +++ b/sope-core/NGExtensions/NGExtensions.xcode/project.pbxproj @@ -38,6 +38,21 @@ settings = { }; }; + AD595AB00745170400B2C064 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = text; + path = README; + refType = 4; + sourceTree = ""; + }; + AD595AB10745170400B2C064 = { + fileRef = AD595AB00745170400B2C064; + isa = PBXBuildFile; + settings = { + }; + }; AD665E37071F00AF00EC5911 = { fileEncoding = 5; indentWidth = 2; @@ -72,6 +87,331 @@ COMPILER_FLAGS = "-I.."; }; }; + ADCD51360743BBBC0071C1A1 = { + children = ( + AD595AB00745170400B2C064, + ADCD51370743BBE10071C1A1, + ADCD51570743BBE60071C1A1, + ADCD515D0743BBFA0071C1A1, + ); + isa = PBXGroup; + path = NGLogging.subproj; + refType = 4; + sourceTree = ""; + }; + ADCD51370743BBE10071C1A1 = { + explicitFileType = text; + fileEncoding = 5; + indentWidth = 8; + isa = PBXFileReference; + path = ChangeLog; + refType = 4; + sourceTree = ""; + tabWidth = 8; + usesTabs = 1; + }; + ADCD51380743BBE10071C1A1 = { + explicitFileType = sourcecode.make; + fileEncoding = 5; + indentWidth = 8; + isa = PBXFileReference; + path = GNUmakefile; + refType = 4; + sourceTree = ""; + tabWidth = 8; + }; + ADCD51390743BBE10071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = NGLogAppender.h; + refType = 4; + sourceTree = ""; + }; + ADCD513A0743BBE10071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = NGLogAppender.m; + refType = 4; + sourceTree = ""; + }; + ADCD513B0743BBE10071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = NGLogConsoleAppender.h; + refType = 4; + sourceTree = ""; + }; + ADCD513C0743BBE10071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = NGLogConsoleAppender.m; + refType = 4; + sourceTree = ""; + }; + ADCD513D0743BBE10071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = NGLogEvent.h; + refType = 4; + sourceTree = ""; + }; + ADCD513E0743BBE10071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = NGLogEvent.m; + refType = 4; + sourceTree = ""; + }; + ADCD513F0743BBE10071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = NGLogger.h; + refType = 4; + sourceTree = ""; + }; + ADCD51400743BBE10071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = NGLogger.m; + refType = 4; + sourceTree = ""; + }; + ADCD51410743BBE10071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = NGLogging.h; + refType = 4; + sourceTree = ""; + }; + ADCD51420743BBE10071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = NGLogSyslogAppender.h; + refType = 4; + sourceTree = ""; + }; + ADCD51430743BBE10071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = NGLogSyslogAppender.m; + refType = 4; + sourceTree = ""; + }; + ADCD51440743BBE10071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = "NSObject+ExtendedLogging.h"; + refType = 4; + sourceTree = ""; + }; + ADCD51450743BBE10071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = "NSObject+ExtendedLogging.m"; + refType = 4; + sourceTree = ""; + }; + ADCD51480743BBE10071C1A1 = { + fileRef = ADCD51390743BBE10071C1A1; + isa = PBXBuildFile; + settings = { + ATTRIBUTES = ( + Public, + ); + }; + }; + ADCD51490743BBE10071C1A1 = { + fileRef = ADCD513A0743BBE10071C1A1; + isa = PBXBuildFile; + settings = { + }; + }; + ADCD514A0743BBE10071C1A1 = { + fileRef = ADCD513B0743BBE10071C1A1; + isa = PBXBuildFile; + settings = { + ATTRIBUTES = ( + Public, + ); + }; + }; + ADCD514B0743BBE10071C1A1 = { + fileRef = ADCD513C0743BBE10071C1A1; + isa = PBXBuildFile; + settings = { + }; + }; + ADCD514C0743BBE10071C1A1 = { + fileRef = ADCD513D0743BBE10071C1A1; + isa = PBXBuildFile; + settings = { + ATTRIBUTES = ( + Public, + ); + }; + }; + ADCD514D0743BBE10071C1A1 = { + fileRef = ADCD513E0743BBE10071C1A1; + isa = PBXBuildFile; + settings = { + }; + }; + ADCD514E0743BBE10071C1A1 = { + fileRef = ADCD513F0743BBE10071C1A1; + isa = PBXBuildFile; + settings = { + ATTRIBUTES = ( + Public, + ); + }; + }; + ADCD514F0743BBE10071C1A1 = { + fileRef = ADCD51400743BBE10071C1A1; + isa = PBXBuildFile; + settings = { + }; + }; + ADCD51500743BBE10071C1A1 = { + fileRef = ADCD51410743BBE10071C1A1; + isa = PBXBuildFile; + settings = { + ATTRIBUTES = ( + Public, + ); + }; + }; + ADCD51510743BBE10071C1A1 = { + fileRef = ADCD51420743BBE10071C1A1; + isa = PBXBuildFile; + settings = { + ATTRIBUTES = ( + Public, + ); + }; + }; + ADCD51520743BBE10071C1A1 = { + fileRef = ADCD51430743BBE10071C1A1; + isa = PBXBuildFile; + settings = { + }; + }; + ADCD51530743BBE10071C1A1 = { + fileRef = ADCD51440743BBE10071C1A1; + isa = PBXBuildFile; + settings = { + ATTRIBUTES = ( + Public, + ); + }; + }; + ADCD51540743BBE10071C1A1 = { + fileRef = ADCD51450743BBE10071C1A1; + isa = PBXBuildFile; + settings = { + }; + }; + ADCD51570743BBE60071C1A1 = { + children = ( + ADCD51380743BBE10071C1A1, + ); + isa = PBXGroup; + name = Makefiles; + refType = 4; + sourceTree = ""; + }; + ADCD515A0743BBF00071C1A1 = { + children = ( + ADCD51410743BBE10071C1A1, + ADCD513F0743BBE10071C1A1, + ADCD52020743D8CA0071C1A1, + ADCD513D0743BBE10071C1A1, + ADCD51390743BBE10071C1A1, + ADCD513B0743BBE10071C1A1, + ADCD51420743BBE10071C1A1, + ADCD51440743BBE10071C1A1, + ); + fileEncoding = 5; + indentWidth = 2; + isa = PBXGroup; + name = NGLogging; + path = ""; + refType = 4; + sourceTree = ""; + }; + ADCD515D0743BBFA0071C1A1 = { + children = ( + ADCD51400743BBE10071C1A1, + ADCD52030743D8CA0071C1A1, + ADCD513E0743BBE10071C1A1, + ADCD513A0743BBE10071C1A1, + ADCD513C0743BBE10071C1A1, + ADCD51430743BBE10071C1A1, + ADCD51450743BBE10071C1A1, + ); + isa = PBXGroup; + name = Classes; + refType = 4; + sourceTree = ""; + }; + ADCD52020743D8CA0071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = NGLoggerManager.h; + refType = 4; + sourceTree = ""; + }; + ADCD52030743D8CA0071C1A1 = { + fileEncoding = 5; + indentWidth = 2; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = NGLoggerManager.m; + refType = 4; + sourceTree = ""; + }; + ADCD52040743D8CA0071C1A1 = { + fileRef = ADCD52020743D8CA0071C1A1; + isa = PBXBuildFile; + settings = { + ATTRIBUTES = ( + Public, + ); + }; + }; + ADCD52050743D8CA0071C1A1 = { + fileRef = ADCD52030743D8CA0071C1A1; + isa = PBXBuildFile; + settings = { + }; + }; ADD45B5E06FEF017004BBD65 = { fileEncoding = 5; indentWidth = 2; @@ -120,6 +460,7 @@ ADD65C2406DA3323007161CA, ADD65C5D06DA336F007161CA, ADD65C5406DA336E007161CA, + ADCD51360743BBBC0071C1A1, ADD65D5D06DA37C7007161CA, ADFE533506E234B7006628C4, ADD65D5906DA372D007161CA, @@ -1176,6 +1517,14 @@ ADD65DE906DA3830007161CA, ADD45B6006FEF017004BBD65, AD4BF6D60703147A006FB665, + ADCD51480743BBE10071C1A1, + ADCD514A0743BBE10071C1A1, + ADCD514C0743BBE10071C1A1, + ADCD514E0743BBE10071C1A1, + ADCD51500743BBE10071C1A1, + ADCD51510743BBE10071C1A1, + ADCD51530743BBE10071C1A1, + ADCD52040743D8CA0071C1A1, ); isa = PBXHeadersBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -1189,6 +1538,7 @@ ADD65F6706DA3B38007161CA, ADD65F6806DA3B38007161CA, ADD65F6906DA3B38007161CA, + AD595AB10745170400B2C064, ); isa = PBXResourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -1265,6 +1615,13 @@ ADD45B6106FEF017004BBD65, AD4BF6EC070314EE006FB665, AD665E3A071F00AF00EC5911, + ADCD51490743BBE10071C1A1, + ADCD514B0743BBE10071C1A1, + ADCD514D0743BBE10071C1A1, + ADCD514F0743BBE10071C1A1, + ADCD51520743BBE10071C1A1, + ADCD51540743BBE10071C1A1, + ADCD52050743D8CA0071C1A1, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -1301,6 +1658,7 @@ GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = NO; GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO; GCC_WARN_UNKNOWN_PRAGMAS = NO; + HEADER_SEARCH_PATHS = ". NGExtensions"; INFOPLIST_FILE = "NGExtensions-Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; OTHER_CFLAGS = ""; @@ -1380,6 +1738,7 @@ ADD65DEF06DA3877007161CA, ADD65DEC06DA3848007161CA, ADD65DF206DA389D007161CA, + ADCD515A0743BBF00071C1A1, ADD65D6206DA382F007161CA, ADD65D7206DA382F007161CA, ADD65D7306DA382F007161CA, @@ -2656,6 +3015,8 @@ ADD65D8C06DA382F007161CA, ADD65D8D06DA3830007161CA, ); + fileEncoding = 5; + indentWidth = 2; isa = PBXGroup; name = NGRuleEngine; path = ""; diff --git a/sope-core/NGExtensions/NGLogging.subproj/ChangeLog b/sope-core/NGExtensions/NGLogging.subproj/ChangeLog new file mode 100644 index 00000000..21714836 --- /dev/null +++ b/sope-core/NGExtensions/NGLogging.subproj/ChangeLog @@ -0,0 +1,30 @@ +2004-11-12 Marcus Mueller + + * NSObject+ExtendedLogging.[hm]: -(id)logger queries NGLoggerManager + now. Also, a new default "NGDefaultLogLevel" triggers default + NSObject based logging now. + + * README: new file + +2004-11-11 Marcus Mueller + + * NGLoggerManager.[hm]: controller providing loggers based on + information from user defaults (currently) + +2004-05-27 Marcus Mueller + + * 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 + + * NGLogSyslogAppender.[hm]: syslog appender, untested. + + * ChangeLog: created diff --git a/sope-core/NGExtensions/NGLogging.subproj/GNUmakefile b/sope-core/NGExtensions/NGLogging.subproj/GNUmakefile new file mode 100644 index 00000000..9f3bcf11 --- /dev/null +++ b/sope-core/NGExtensions/NGLogging.subproj/GNUmakefile @@ -0,0 +1,21 @@ +# GNUstep makefile + +-include ../../../config.make +include ../../common.make + +SUBPROJECT_NAME = NGLogging + +NGLogging_OBJC_FILES = \ + NGLogger.m \ + NGLoggerManager.m \ + NGLogEvent.m \ + NGLogAppender.m \ + NGLogConsoleAppender.m \ + NGLogSyslogAppender.m \ + NSObject+ExtendedLogging.m \ + +ADDITIONAL_INCLUDE_DIRS += -I. -I../NGExtensions/ -I.. -I../.. + +-include GNUmakefile.preamble +include $(GNUSTEP_MAKEFILES)/subproject.make +-include GNUmakefile.postamble diff --git a/sope-core/NGExtensions/NGLogging.subproj/NGLogAppender.m b/sope-core/NGExtensions/NGLogging.subproj/NGLogAppender.m new file mode 100644 index 00000000..86211367 --- /dev/null +++ b/sope-core/NGExtensions/NGLogging.subproj/NGLogAppender.m @@ -0,0 +1,64 @@ +/* + 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 "NGLogAppender.h" +#include "NSObject+ExtendedLogging.h" +#include "NGLogEvent.h" + +@implementation NGLogAppender + +- (void)appendLogEvent:(NGLogEvent *)_event { + [self subclassResponsibility:_cmd]; +} + +- (NSString *)formattedEvent:(NGLogEvent *)_event { + return [NSString stringWithFormat:@"[%@] %@", + [self localizedNameOfLogLevel:[_event level]], + [_event message]]; +} + +- (NSString *)localizedNameOfLogLevel:(NGLogLevel)_level { + NSString *name; + + switch (_level) { + case NGLogLevelDebug: + name = @"DEBUG"; + break; + case NGLogLevelInfo: + name = @"INFO"; + break; + case NGLogLevelWarn: + name = @"WARN"; + break; + case NGLogLevelError: + name = @"ERROR"; + break; + case NGLogLevelFatal: + name = @"FATAL"; + break; + default: + name = @""; + break; + } + return name; +} + +@end diff --git a/sope-core/NGExtensions/NGLogging.subproj/NGLogConsoleAppender.m b/sope-core/NGExtensions/NGLogging.subproj/NGLogConsoleAppender.m new file mode 100644 index 00000000..8d285b42 --- /dev/null +++ b/sope-core/NGExtensions/NGLogging.subproj/NGLogConsoleAppender.m @@ -0,0 +1,31 @@ +/* + 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 "NGLogConsoleAppender.h" +#include "NGLogEvent.h" + +@implementation NGLogConsoleAppender + +- (void)appendLogEvent:(NGLogEvent *)_event { + NSLog([self formattedEvent:_event]); +} + +@end diff --git a/sope-core/NGExtensions/NGLogging.subproj/NGLogEvent.m b/sope-core/NGExtensions/NGLogging.subproj/NGLogEvent.m new file mode 100644 index 00000000..eb68b136 --- /dev/null +++ b/sope-core/NGExtensions/NGLogging.subproj/NGLogEvent.m @@ -0,0 +1,53 @@ +/* + 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 + +- (id)initWithLevel:(NGLogLevel)_level message:(NSString *)_msg { + if((self = [super init])) { + self->date = [NSDate timeIntervalSinceReferenceDate]; + self->level = _level; + ASSIGN(self->msg, _msg); + } + return self; +} + +- (void)dealloc { + [self->msg release]; + [super dealloc]; +} + +- (NGLogLevel)level { + return self->level; +} + +- (NSString *)message { + return self->msg; +} + +- (NSDate *)date { + return [NSDate dateWithTimeIntervalSinceReferenceDate:self->date]; +} + +@end diff --git a/sope-core/NGExtensions/NGLogging.subproj/NGLogSyslogAppender.m b/sope-core/NGExtensions/NGLogging.subproj/NGLogSyslogAppender.m new file mode 100644 index 00000000..dc65fdd3 --- /dev/null +++ b/sope-core/NGExtensions/NGLogging.subproj/NGLogSyslogAppender.m @@ -0,0 +1,109 @@ +/* + 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" +#include +#include + +@interface NGLogSyslogAppender (PrivateAPI) +- (int)syslogLevelForLogLevel:(NGLogLevel)_level; +@end + +@implementation NGLogSyslogAppender + +static NSString *defaultSyslogIdentifier = nil; + ++ (void)initialize { + NSUserDefaults *ud; + static BOOL isInitialized = NO; + + if(isInitialized) + return; + + ud = [NSUserDefaults standardUserDefaults]; + defaultSyslogIdentifier = + [[ud stringForKey:@"NGLogSyslogIdentifier"] retain]; + + isInitialized = YES; +} + ++ (id)sharedAppender { + static id sharedAppender = nil; + if(sharedAppender == nil) { + sharedAppender = [[self alloc] init]; + } + return sharedAppender; +} + +- (id)init { + return [self initWithIdentifier:defaultSyslogIdentifier]; +} + +- (id)initWithIdentifier:(NSString *)_ident { + if((self = [super init])) { +#warning ** default flags? + openlog([_ident cString], LOG_PID | LOG_NDELAY, LOG_USER); + } + return self; +} + +- (void)dealloc { + closelog(); + [super dealloc]; +} + +- (void)appendLogEvent:(NGLogEvent *)_event { + NSString *formattedMsg; + int level; + + formattedMsg = [self formattedEvent:_event]; + level = [self syslogLevelForLogLevel:[_event level]]; + syslog(level, [formattedMsg cString]); +} + +- (int)syslogLevelForLogLevel:(NGLogLevel)_level { + int level; + + switch (_level) { + case NGLogLevelDebug: + level = LOG_DEBUG; + break; + case NGLogLevelInfo: + level = LOG_INFO; + break; + case NGLogLevelWarn: + level = LOG_WARNING; + break; + case NGLogLevelError: + level = LOG_ERR; + break; + case NGLogLevelFatal: + level = LOG_ALERT; // LOG_EMERG is broadcast to all users... + break; + default: + level = LOG_NOTICE; + break; + } + return level; +} + +@end diff --git a/sope-core/NGExtensions/NGLogging.subproj/NGLogger.m b/sope-core/NGExtensions/NGLogging.subproj/NGLogger.m new file mode 100644 index 00000000..5cfcd907 --- /dev/null +++ b/sope-core/NGExtensions/NGLogging.subproj/NGLogger.m @@ -0,0 +1,110 @@ +/* + 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 "NGLogger.h" +#include "common.h" +#include "NGLogEvent.h" +#include "NGLogAppender.h" + +@implementation NGLogger + +- (id)init { + self = [self initWithLogLevel:NGLogLevelAll]; + return self; +} + +- (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 + ud = [NSUserDefaults standardUserDefaults]; + appenderClassName = [ud stringForKey:@"NGLogDefaultAppenderClass"]; + if(appenderClassName == nil) + appenderClassName = @"NGLogConsoleAppender"; + self->_appender = [[NSClassFromString(appenderClassName) alloc] init]; + } + return self; +} + +- (void)dealloc { + [self->_appender release]; + [super dealloc]; +} + + +- (void)setLogLevel:(NGLogLevel)_level { + self->logLevel = _level; +} + +- (NGLogLevel)logLevel { + return self->logLevel; +} + +- (void)logLevel:(NGLogLevel)_level withFormat:(NSString *)_fmt, ... { + NSString *msg; + va_list va; + + if(self->logLevel > _level) + return; + + va_start(va, _fmt); + msg = [[NSString 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]; +} + +- (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; +} + +@end diff --git a/sope-core/NGExtensions/NGLogging.subproj/NGLoggerManager.m b/sope-core/NGExtensions/NGLogging.subproj/NGLoggerManager.m new file mode 100644 index 00000000..d56129f2 --- /dev/null +++ b/sope-core/NGExtensions/NGLogging.subproj/NGLoggerManager.m @@ -0,0 +1,107 @@ +/* + 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 "NGLoggerManager.h" +#include "NSObject+ExtendedLogging.h" +#include "NGLogger.h" + +@interface NGLoggerManager (PrivateAPI) +- (NGLogLevel)_logLevelForString:(NSString *)_defaultValue; +@end + +@implementation NGLoggerManager + +static NGLoggerManager *sharedInstance; +static NSNull *sharedNull; + ++ (void)initialize { + static BOOL didInit = NO; + + if(didInit) + return; + + didInit = YES; + sharedInstance = [[self alloc] init]; + sharedNull = [NSNull null]; +} + ++ (id)defaultManager { + return sharedInstance; +} + +- (id)init { + self = [super init]; + if(self) { + self->loggerMap = [[NSMutableDictionary alloc] initWithCapacity:50]; + } + return self; +} + +- (void)dealloc { + [self->loggerMap release]; + [super dealloc]; +} + +- (NGLogger *)loggerForDefaultKey:(NSString *)_defaultKey { + id logger; + + logger = [self->loggerMap objectForKey:_defaultKey]; + if(!logger) { + NSUserDefaults *ud; + NSString *levelId; + NGLogLevel level; + + ud = [NSUserDefaults standardUserDefaults]; + levelId = [[ud stringForKey:_defaultKey] uppercaseString]; + level = [self _logLevelForString:levelId]; + if(level == NGLogLevelOff) { + [self->loggerMap setObject:sharedNull forKey:_defaultKey]; + logger = sharedNull; + } + else { + logger = [[NGLogger alloc] initWithLogLevel:level]; + [self->loggerMap setObject:logger forKey:_defaultKey]; + [logger release]; + } + } + return (logger != sharedNull) ? logger : nil; +} + +/* Private */ + +- (NGLogLevel)_logLevelForString:(NSString *)_defaultValue { + if(!_defaultValue || [_defaultValue isEqualToString:@"NO"]) + return NGLogLevelOff; + else if([_defaultValue isEqualToString:@"YES"] || + [_defaultValue isEqualToString:@"DEBUG"]) + return NGLogLevelDebug; + else if([_defaultValue isEqualToString:@"INFO"]) + return NGLogLevelInfo; + else if([_defaultValue isEqualToString:@"WARN"]) + return NGLogLevelWarn; + else if([_defaultValue isEqualToString:@"ERROR"]) + return NGLogLevelError; + else if([_defaultValue isEqualToString:@"FATAL"]) + return NGLogLevelFatal; + return NGLogLevelAll; +} + +@end diff --git a/sope-core/NGExtensions/NGLogging.subproj/NSObject+ExtendedLogging.m b/sope-core/NGExtensions/NGLogging.subproj/NSObject+ExtendedLogging.m new file mode 100644 index 00000000..99ed6790 --- /dev/null +++ b/sope-core/NGExtensions/NGLogging.subproj/NSObject+ExtendedLogging.m @@ -0,0 +1,131 @@ +/* + 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 "NSObject+ExtendedLogging.h" +#include "NGLogger.h" +#include "NGLoggerManager.h" + +@implementation NSObject (NGExtendedLogging) + +- (id)logger { + static id sharedLogger = nil; + static BOOL shouldLog = YES; + if(sharedLogger == nil && shouldLog) { + NGLoggerManager *lm; + lm = [NGLoggerManager defaultManager]; + sharedLogger = [lm loggerForDefaultKey:@"NGDefaultLogLevel"]; + if(!sharedLogger) + shouldLog = NO; + } + return sharedLogger; +} + +- (void)logDebugWithFormat:(NSString *)_fmt, ... { + NSString *msg; + va_list va; + + va_start(va, _fmt); + msg = [[NSString alloc] initWithFormat:_fmt arguments:va]; + va_end(va); + [self logLevel:NGLogLevelDebug message:msg]; + [msg release]; +} + +- (void)logInfoWithFormat:(NSString *)_fmt, ... { + NSString *msg; + va_list va; + + va_start(va, _fmt); + msg = [[NSString alloc] initWithFormat:_fmt arguments:va]; + va_end(va); + [self logLevel:NGLogLevelInfo message:msg]; + [msg release]; +} + +- (void)logWarnWithFormat:(NSString *)_fmt, ... { + NSString *msg; + va_list va; + + va_start(va, _fmt); + msg = [[NSString alloc] initWithFormat:_fmt arguments:va]; + va_end(va); + [self logLevel:NGLogLevelWarn message:msg]; + [msg release]; +} + +- (void)logErrorWithFormat:(NSString *)_fmt, ... { + NSString *msg; + va_list va; + + va_start(va, _fmt); + msg = [[NSString alloc] initWithFormat:_fmt arguments:va]; + va_end(va); + [self logLevel:NGLogLevelError message:msg]; + [msg release]; +} + +- (void)logFatalWithFormat:(NSString *)_fmt, ... { + NSString *msg; + va_list va; + + va_start(va, _fmt); + msg = [[NSString alloc] initWithFormat:_fmt arguments:va]; + va_end(va); + [self logLevel:NGLogLevelFatal message:msg]; + [msg release]; +} + +- (void)logLevel:(NGLogLevel)_level message:(NSString *)_msg { + [[self logger] logLevel:_level message:_msg]; +} + +- (void)logLevel:(NGLogLevel)_level withFormat:(NSString *)_fmt, ... { + NSString *msg; + va_list va; + + va_start(va, _fmt); + msg = [[NSString alloc] initWithFormat:_fmt arguments:va]; + va_end(va); + [[self logger] logLevel:_level withFormat:msg]; + [msg release]; +} + +- (BOOL)isLogDebugEnabled { + return [[self logger] isLogDebugEnabled]; +} + +- (BOOL)isLogInfoEnabled { + return [[self logger] isLogInfoEnabled]; +} + +- (BOOL)isLogWarnEnabled { + return [[self logger] isLogWarnEnabled]; +} + +- (BOOL)isLogErrorEnabled { + return [[self logger] isLogErrorEnabled]; +} + +- (BOOL)isLogFatalEnabled { + return [[self logger] isLogFatalEnabled]; +} + +@end diff --git a/sope-core/NGExtensions/NGLogging.subproj/README b/sope-core/NGExtensions/NGLogging.subproj/README new file mode 100644 index 00000000..445c721e --- /dev/null +++ b/sope-core/NGExtensions/NGLogging.subproj/README @@ -0,0 +1,31 @@ +NGLogging OVERVIEW +================== + +TBD: write overview! + + +NOTES +===== + +NGLoggerManager: +- provide some extra config for configuration of appenders for loggers + +NGLogger: +- what about loggingPrefix? +- provide API for setting appenders + +NSObject+ExtendedLogging: +- should check if -loggingPrefix is defined. If YES should provide this to + logger + +NGLogEvent +- should remember its logger? -> probably important for filtering + + +APPENDER NOTES +============== + +- We're probably not interested in providing lots of appenders for lots of + different loggers. Most of the time we have something like a default + appender, say NGLogConsoleAppender during development and NGLogSyslogAppender + for deployment (or file appenders) diff --git a/sope-core/NGExtensions/Version b/sope-core/NGExtensions/Version index 5a96beaf..5ddb9af7 100644 --- a/sope-core/NGExtensions/Version +++ b/sope-core/NGExtensions/Version @@ -1,6 +1,6 @@ # version -SUBMINOR_VERSION:=126 +SUBMINOR_VERSION:=127 # v4.3.115 requires libFoundation v1.0.59 # v4.2.72 requires libEOControl v4.2.39 -- 2.39.5