]> err.no Git - sope/commitdiff
minor logging changes
authorznek <znek@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Mon, 15 Nov 2004 22:17:46 +0000 (22:17 +0000)
committerznek <znek@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Mon, 15 Nov 2004 22:17:46 +0000 (22:17 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@371 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-appserver/NGObjWeb/ChangeLog
sope-appserver/NGObjWeb/Version
sope-appserver/NGObjWeb/WOCoreApplication.m
sope-appserver/NGObjWeb/WOHttpAdaptor/WOHttpAdaptor.m
sope-appserver/NGObjWeb/WOHttpAdaptor/common.h

index 14bb58ea0b93bf179125742313f1b0a98603df96..9b2429f1e567cee4ee0c23ea517794ec2093b1da 100644 (file)
@@ -1,3 +1,15 @@
+2004-11-15  Marcus Mueller  <znek@mulle-kybernetik.com>
+
+       * 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  <helge.hess@opengroupware.org>
 
        * WOApplication.m: changed wrapper-missing-log from warn to debug
index 9b30ff55b4d71eac9775ab7ba1bdb816827982cd..3a6ac51c364e1f6fcd8b0d0bb0b05202198f344f 100644 (file)
@@ -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
index dd0888a9b71187d79bf16a0e4e1a517d8b15f2de..51172472241921552fef41e783cb6ebe54999f07 100644 (file)
@@ -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 {
index e20e2c1c7ee1390dc988596ee3d99f13a4e1237c..c3d506b06e42c401ed6131ea47eed9b4e4035c05 100644 (file)
@@ -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<NGSocketAddress> 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);
   }
 }
index ddc6693c1a5854cb45057ba4b45730e95add6923..974f06ec6f47633fdc0125131fcc570c626ceb98 100644 (file)
@@ -22,5 +22,6 @@
 #import <Foundation/Foundation.h>
 
 #include <NGExtensions/NGExtensions.h>
+#include <NGExtensions/NGLogging.h>
 #include <NGStreams/NGStreams.h>
 #include <NGStreams/NGNet.h>