From 52608eccd9aa93c7e265efb1f2a7ba3b2c719b8c Mon Sep 17 00:00:00 2001 From: znek Date: Mon, 15 Nov 2004 22:17:46 +0000 Subject: [PATCH] minor logging changes git-svn-id: http://svn.opengroupware.org/SOPE/trunk@371 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/NGObjWeb/ChangeLog | 12 +++ sope-appserver/NGObjWeb/Version | 2 +- sope-appserver/NGObjWeb/WOCoreApplication.m | 7 +- .../NGObjWeb/WOHttpAdaptor/WOHttpAdaptor.m | 76 +++++++++---------- .../NGObjWeb/WOHttpAdaptor/common.h | 1 + 5 files changed, 54 insertions(+), 44 deletions(-) diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 14bb58ea..9b2429f1 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,15 @@ +2004-11-15 Marcus Mueller + + * v4.5.87 + + * WOCoreApplication.m: needed to define a private +logger to enable + proper logging in class methods. + + * WOHttpAdaptor/common.h: add new logging API to common includes + + * WOHttpAdaptor/WOHttpAdaptor.m: rewrote logging to use new logging + API. Added an own (conditional) logger for performance logging. + 2004-11-13 Helge Hess * WOApplication.m: changed wrapper-missing-log from warn to debug diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index 9b30ff55..3a6ac51c 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=86 +SUBMINOR_VERSION:=87 # v4.5.84 required libNGExtensions v4.5.127 # v4.3.42 requires libNGExtensions v4.3.116 diff --git a/sope-appserver/NGObjWeb/WOCoreApplication.m b/sope-appserver/NGObjWeb/WOCoreApplication.m index dd0888a9..51172472 100644 --- a/sope-appserver/NGObjWeb/WOCoreApplication.m +++ b/sope-appserver/NGObjWeb/WOCoreApplication.m @@ -49,6 +49,7 @@ NGObjWeb_DECLARE NSString *WOApplicationDidTerminateNotification = @interface WOCoreApplication(PrivateMethods) + (void)_initDefaults; ++ (id)logger; - (NSDictionary *)memoryStatistics; - (WOResponse *)handleException:(NSException *)_exc; @end @@ -190,7 +191,7 @@ static NSMutableArray *activeApps = nil; // THREAD /* NGLogging */ -- (id)logger { ++ (id)logger { static id sharedLogger = nil; if(sharedLogger == nil) { sharedLogger = [[NGLogger alloc] initWithLogLevel:NGLogLevelDebug]; @@ -198,6 +199,10 @@ static NSMutableArray *activeApps = nil; // THREAD return sharedLogger; } +- (id)logger { + return [[self class] logger]; +} + /* signals */ - (void)processHupSignal:(int)_signal { diff --git a/sope-appserver/NGObjWeb/WOHttpAdaptor/WOHttpAdaptor.m b/sope-appserver/NGObjWeb/WOHttpAdaptor/WOHttpAdaptor.m index e20e2c1c..c3d506b0 100644 --- a/sope-appserver/NGObjWeb/WOHttpAdaptor/WOHttpAdaptor.m +++ b/sope-appserver/NGObjWeb/WOHttpAdaptor/WOHttpAdaptor.m @@ -42,8 +42,6 @@ # warning extensive pools are enabled ... #endif -static BOOL HTTP_PERFLOG = NO; - #include "WOHttpAdaptor.h" #include "WORecordRequestStream.h" #include "WOHttpTransaction.h" @@ -62,40 +60,37 @@ static BOOL HTTP_PERFLOG = NO; @end /* WOHttpAdaptor */ -@interface WOHttpAdaptor(PrivateMethods2) - -- (void)logWithFormat:(NSString *)_format, ...; - -@end - @interface WOCoreApplication(Port) - (NSNumber *)port; @end @implementation WOHttpAdaptor +static NGLogger *perfLogger = nil; static BOOL WOHttpAdaptor_LogStream = NO; static BOOL WOContactSNS = NO; static BOOL WOCoreOnHTTPAdaptorException = NO; -static NSString *WOPort = nil; -static int WOHttpAdaptorSendTimeout = 10; -static int WOHttpAdaptorReceiveTimeout = 10; -static id allow = nil; -static BOOL debugOn = NO; +static NSString *WOPort = nil; +static int WOHttpAdaptorSendTimeout = 10; +static int WOHttpAdaptorReceiveTimeout = 10; +static id allow = nil; +static BOOL debugOn = NO; + (BOOL)optionLogStream { return WOHttpAdaptor_LogStream; } + (BOOL)optionLogPerf { - return HTTP_PERFLOG; + return perfLogger != nil ? YES : NO; } + (int)version { return [super version] + 1 /* v2 */; } + (void)initialize { - NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - static BOOL didInit = NO; + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + NGLoggerManager *um = [NGLoggerManager defaultLoggerManager]; + static BOOL didInit = NO; + if (didInit) return; didInit = YES; @@ -104,7 +99,7 @@ static BOOL debugOn = NO; NSStringFromClass([self superclass]), [super version]); WOHttpAdaptor_LogStream = [ud boolForKey:@"WOHttpAdaptor_LogStream"]; - HTTP_PERFLOG = [[ud objectForKey:@"WOProfileHttpAdaptor"] boolValue]; + perfLogger = [um loggerForDefaultKey:@"WOProfileHttpAdaptor"]; // TODO: those two should be queried on demand to allow different defaults WOPort = [[ud stringForKey:@"WOPort"] copy]; @@ -132,7 +127,7 @@ static BOOL debugOn = NO; } if (WOCoreOnHTTPAdaptorException) - NSLog(@"WARNING: will dump core on HTTP adaptor exception!"); + [self logWarnWithFormat:@"will dump core on HTTP adaptor exception!"]; } - (id)autoBindAddress { @@ -213,14 +208,14 @@ static BOOL debugOn = NO; self->address = [self->address retain]; if (self->address == nil) { - [_application logWithFormat: + [_application logErrorWithFormat: @"got no address for HTTP server (using arg '%@')", arg]; [self release]; return nil; } if (!WOContactSNS) { - [_application logWithFormat:@"%@ listening on address %@", + [_application logInfoWithFormat:@"%@ listening on address %@", NSStringFromClass([self class]), [(id)self->address stringValue]]; } @@ -254,7 +249,7 @@ static BOOL debugOn = NO; /* events */ - (void)handleSIGPIPE:(int)_signal { - [self logWithFormat:@"caught SIGPIPE !"]; + [self logWarnWithFormat:@"caught SIGPIPE !"]; } - (void)registerForEvents { @@ -281,7 +276,7 @@ static BOOL debugOn = NO; self->address = [[self->socket localAddress] retain]; - [self logWithFormat:@"bound to kernel assigned address %@: %@", + [self logInfoWithFormat:@"bound to kernel assigned address %@: %@", self->address, self->socket]; } } @@ -354,22 +349,18 @@ static BOOL debugOn = NO; /* logging */ -- (void)logWithFormat:(NSString *)_format, ... { - NSString *value = nil; - va_list ap; - - va_start(ap, _format); - value = [[NSString alloc] initWithFormat:_format arguments:ap]; - va_end(ap); - - NSLog(@"WOHttpAdaptor: %@", value); - [value release]; value = nil; +- (id)logger { + static id sharedLogger = nil; + if(sharedLogger == nil) { + sharedLogger = [[NGLogger alloc] initWithLogLevel:NGLogLevelDebug]; + } + return sharedLogger; } /* run-loop */ - (void)_serverCatched:(NSException *)_exc { - [self logWithFormat:@"http server caught: %@", _exc]; + [self logErrorWithFormat:@"http server caught: %@", _exc]; if (WOCoreOnHTTPAdaptorException) abort(); } @@ -377,7 +368,7 @@ static BOOL debugOn = NO; WOHttpTransaction *tx; if (_socket == nil) { - [self logWithFormat:@"got no socket for transaction ??"]; + [self logErrorWithFormat:@"got no socket for transaction ??"]; return NO; } @@ -401,7 +392,7 @@ static BOOL debugOn = NO; #endif NSTimeInterval t; - if (HTTP_PERFLOG) + if (perfLogger) *(&t) = [[NSDate date] timeIntervalSince1970]; [self->lock lock]; @@ -433,10 +424,10 @@ static BOOL debugOn = NO; self->activeThreadCount--; [self->lock unlock]; - if (HTTP_PERFLOG) { + if (perfLogger) { t = [[NSDate date] timeIntervalSince1970] - t; - [self logWithFormat:@"handling of request took %4.3fs.", - t < 0.0 ? -1.0 : t]; + [perfLogger logInfoWithFormat:@"handling of request took %4.3fs.", + t < 0.0 ? -1.0 : t]; } } @@ -449,7 +440,7 @@ static BOOL debugOn = NO; id remote; if ((remote = [_connection remoteAddress]) == nil) { - [self logWithFormat: + [self logErrorWithFormat: @"missing remote address for connection: %@", _connection]; return nil; @@ -490,7 +481,7 @@ static BOOL debugOn = NO; return _connection; } - [self logWithFormat:@"ACCESS DENIED: %@", ipAddr]; + [self logErrorWithFormat:@"ACCESS DENIED: %@", ipAddr]; _connection = nil; } @@ -532,7 +523,7 @@ static BOOL debugOn = NO; [NSThread detachNewThreadSelector:@selector(_handleAcceptedConnection:) toTarget:self withObject:[connection retain]]; - [self logWithFormat:@"detached new thread for request."]; + [self logInfoWithFormat:@"detached new thread for request."]; //[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:10]]; } connection = nil; @@ -551,7 +542,8 @@ static BOOL debugOn = NO; [self->socket close]; [self->socket release]; self->socket = nil; } - NSLog(@"adaptor stops application: %@ ...", self->application); + [self logInfoWithFormat:@"adaptor stops application: %@ ...", + self->application]; exit(0); } } diff --git a/sope-appserver/NGObjWeb/WOHttpAdaptor/common.h b/sope-appserver/NGObjWeb/WOHttpAdaptor/common.h index ddc6693c..974f06ec 100644 --- a/sope-appserver/NGObjWeb/WOHttpAdaptor/common.h +++ b/sope-appserver/NGObjWeb/WOHttpAdaptor/common.h @@ -22,5 +22,6 @@ #import #include +#include #include #include -- 2.39.2