/*
- Copyright (C) 2000-2004 SKYRIX Software AG
+ Copyright (C) 2000-2005 SKYRIX Software AG
- This file is part of OpenGroupware.org.
+ This file is part of SOPE.
- OGo is free software; you can redistribute it and/or modify it under
+ SOPE 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
+ SOPE 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
+ License along with SOPE; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
@interface WOCoreApplication(PrivateMethods)
+ (void)_initDefaults;
++ (id)logger;
- (NSDictionary *)memoryStatistics;
- (WOResponse *)handleException:(NSException *)_exc;
@end
@implementation WOCoreApplication
-static BOOL perflog = NO;
-static BOOL outputValidateOn = NO;
-static Class NSDateClass = Nil;
+static BOOL outputValidateOn = NO;
+static Class NSDateClass = Nil;
+static NGLogger *logger = nil;
+static NGLogger *perfLogger = nil;
+ (int)version {
return 1;
+ (id)application {
if (WOApp == nil) {
- NSLog(@"WARNING(%s): some code called +application without "
- @"an active app !", __PRETTY_FUNCTION__);
+ [self warnWithFormat:@"%s: some code called +application without an "
+ @"active app !", __PRETTY_FUNCTION__];
#if DEBUG && 0
# warning REMOVE THAT ABORT IN PRODUCTION CODE !!!
abort();
unsigned idx;
if (WOApp != self) {
- [self logWithFormat:
+ [self warnWithFormat:
@"tried to deactivate inactive application !\n"
@" self: %@\n"
@" active: %@",
properly if this is called first.
*/
static BOOL didInit = NO;
- NSUserDefaults *ud;
+ NSUserDefaults *ud;
+ NGLoggerManager *lm;
if (didInit) return;
didInit = YES;
[self _initDefaults];
-
- ud = [NSUserDefaults standardUserDefaults];
- perflog = [ud boolForKey:@"WOProfileApplication"];
+
+ lm = [NGLoggerManager defaultLoggerManager];
+ logger = [lm loggerForClass:self];
+ perfLogger = [lm loggerForDefaultKey:@"WOProfileApplication"];
+
+ ud = [NSUserDefaults standardUserDefaults];
outputValidateOn = [ud boolForKey:@"WOOutputValidationEnabled"];
NSDateClass = [NSDate class];
}
[super dealloc];
}
+/* NGLogging */
+
++ (id)logger {
+ return logger;
+}
+
+- (id)logger {
+ return logger;
+}
+
/* signals */
- (void)processHupSignal:(int)_signal {
adaptorClass = NSClassFromString(_name);
if (adaptorClass == Nil) {
- [self logWithFormat:@"ERROR: did not find adaptor class %@", _name];
+ [self errorWithFormat:@"did not find adaptor class %@", _name];
return nil;
}
WOResponse *r = nil;
if ([self respondsToSelector:@selector(handleException:)]) {
- NSLog(@"WARNING: calling deprecated -handleException method !");
+ [self warnWithFormat:@"calling deprecated -handleException method !"];
return [self handleException:_exc];
}
#if 0 && DEBUG
- [self logWithFormat:@"%@: caught (without context):\n %@.", self, _exc];
+ [self errorWithFormat:@"%@: caught (without context):\n %@.", self, _exc];
abort();
#endif
if (_ctx == nil) {
- [self logWithFormat:@"%@: caught (without context):\n %@.", self, _exc];
+ [self errorWithFormat:@"%@: caught (without context):\n %@.",
+ self, _exc];
[self terminate];
}
else if (rq == nil) {
- [self logWithFormat:@"%@: caught (without request):\n %@.", self, _exc];
+ [self errorWithFormat:@"%@: caught (without request):\n %@.",
+ self, _exc];
[self terminate];
}
else {
}
if ((r = [WOResponse responseWithRequest:rq]) == nil)
- [self logWithFormat:@"could not create response !"];
+ [self warnWithFormat:@"could not create response !"];
[r setStatus:500];
return r;
adaptor = [self adaptorWithName:[moreAdaptors objectAtIndex:i]
arguments:nil];
if (adaptor == nil) {
- [self logWithFormat:@"could not find WOAdaptor '%@' !",
+ [self warnWithFormat:@"could not find WOAdaptor '%@' !",
[moreAdaptors objectAtIndex:i]];
continue;
}
static BOOL didWarn = NO;
if (!didWarn) {
- [self logWithFormat:
- @"WARNING: output validation is enabled, this will "
+ [self warnWithFormat:
+ @"output validation is enabled, this will "
@"slow down request processing!"];
didWarn = YES;
}
if ([self hideValidationIssue:issue])
continue;
[self logWithFormat:@"validate-output[%@]: %@",
- [(NSException *)issue name], [issue reason]];
+ [(NSException *)issue name], [issue reason]];
continue;
}
WOResponse *response = nil;
NSTimeInterval startDispatch = 0.0;
- if (perflog)
+ if (perfLogger)
startDispatch = [[NSDateClass date] timeIntervalSince1970];
/* let request handler process the request */
{
NSTimeInterval startDispatch = 0.0;
- if (perflog)
+ if (perfLogger)
startDispatch = [[NSDateClass date] timeIntervalSince1970];
/* the call ;-) */
response = [handler handleRequest:_request];
- if (perflog) {
+ if (perfLogger) {
NSTimeInterval rt;
rt = [[NSDateClass date] timeIntervalSince1970] - startDispatch;
- NSLog(@" [woapp-rq]: request handler took %4.3fs.",
- rt < 0.0 ? -1.0 : rt);
+ [perfLogger logWithFormat:@"[woapp-rq]: request handler took %4.3fs.",
+ rt < 0.0 ? -1.0 : rt];
}
}
if (outputValidateOn)
[self validateOutputOfResponse:response];
- if (perflog) {
+ if (perfLogger) {
NSTimeInterval rt;
rt = [[NSDateClass date] timeIntervalSince1970] - startDispatch;
- NSLog(@"[woapp]: dispatchRequest took %4.3fs.",
- rt < 0.0 ? -1.0 : rt);
+ [perfLogger logWithFormat:@"[woapp]: dispatchRequest took %4.3fs.",
+ rt < 0.0 ? -1.0 : rt];
}
return response;
WORequestHandler *handler;
if ([self respondsToSelector:@selector(handleRequest:)]) {
- [self logWithFormat:
- @"WARNING: calling deprecated -handleRequest: method .."];
+ [self warnWithFormat:
+ @"calling deprecated -handleRequest: method .."];
return [self handleRequest:_request];
}
/* find request handler for request */
if ((handler = [self handlerForRequest:_request]) == nil) {
- [self logWithFormat:@"ERROR: got no request handler for request: %@ !",
+ [self errorWithFormat:@"got no request handler for request: %@ !",
_request];
return nil;
}
apath = [self findNGObjWebResource:@"Defaults" ofType:@"plist"];
if (apath == nil)
- NSLog(@"ERROR: cannot find Defaults.plist resource of NGObjWeb library!");
+ [self errorWithFormat:@"cannot find Defaults.plist resource of NGObjWeb library!"];
+#if HEAVY_DEBUG
+ else
+ [self debugWithFormat:@"Note: loading default defaults: %@", apath];
+#endif
owDefaults = [NSDictionary dictionaryWithContentsOfFile:apath];
if (owDefaults) {
[[NSUserDefaults standardUserDefaults] registerDefaults:owDefaults];
#if HEAVY_DEBUG
- [self logWithFormat:@"did register NGObjWeb defaults: %@\n%@",
- apath, owDefaults];
+ [self debugWithFormat:@"did register NGObjWeb defaults: %@\n%@",
+ apath, owDefaults];
#endif
}
else {
- [self logWithFormat:@"ERROR: could not load NGObjWeb defaults: '%@'",
+ [self errorWithFormat:@"could not load NGObjWeb defaults: '%@'",
apath];
}
}
woport = [[self userDefaults] objectForKey:@"WOPort"];
if ([woport isKindOfClass:[NSNumber class]])
return woport;
-
woport = [woport stringValue];
+ if ([woport length] > 0 && isdigit([woport characterAtIndex:0]))
+ return [NSNumber numberWithInt:[woport intValue]];
+
addr = NGSocketAddressFromString(woport);
if ([addr isKindOfClass:[NGInternetSocketAddress class]])
return [NSNumber numberWithInt:[(NGInternetSocketAddress *)addr port]];
-
+
+ [self fatalWithFormat:@"GOT NO PORT FOR ADDR: %@ (%@)", addr, woport];
return nil;
}