2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "NGLogEventFormatter.h"
25 #include "NGLogLevel.h"
29 @interface NGLogEventDetailedFormatter : NGLogEventFormatter
35 #include "NGLogEvent.h"
37 #include "NSProcessInfo+misc.h"
39 @implementation NGLogEventDetailedFormatter
41 static unsigned char *processName = NULL;
42 static NSProcessInfo *processInfo = nil;
44 static char *monthNames[14] = {
46 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
47 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
52 static BOOL didInit = NO;
59 processInfo = [[NSProcessInfo processInfo] retain];
60 pn = [processInfo processName];
61 len = [pn cStringLength];
62 processName = malloc(len + 4);
63 [pn getCString:processName];
66 static __inline__ unsigned char * levelPrefixForEvent(NGLogEvent *_event) {
67 switch ([_event level]) {
68 case NGLogLevelWarn: return "[WARN] ";
69 case NGLogLevelError: return "[ERROR] ";
70 case NGLogLevelFatal: return "[FATAL] ";
75 - (NSString *)formattedEvent:(NGLogEvent *)_event {
79 fe = [NSMutableString stringWithCapacity:160];
80 /* timestamp, process name, process id, level prefix */
82 [fe appendFormat:@"%s %02i %02i:%02i:%02i %s [%d]: %s",
83 monthNames[[date monthOfYear]],
85 [date hourOfDay], [date minuteOfHour], [date secondOfMinute],
87 /* Note: pid can change after a fork() */
88 #if NeXT_Foundation_LIBRARY || COCOA_Foundation_LIBRARY
89 [processInfo processIdentifier],
91 [[processInfo processId] intValue],
93 levelPrefixForEvent(_event)];
96 [fe appendString:[_event message]];
100 @end /* NGLogEventDetailedFormatter */