28#define OOLOG_POISON_NSLOG 0
41#define PER_THREAD_INDENTATION 1
43#if PER_THREAD_INDENTATION
45#define USE_INDENT_GLOBALS 1
46#define THREAD_LOCAL __thread
48#define USE_INDENT_GLOBALS 0
53#define USE_INDENT_GLOBALS 1
58#define OOLOG_NOT_INITED 1
59#define OOLOG_SETTING_SET 0
60#define OOLOG_SETTING_RETRIEVE 0
61#define OOLOG_UNDEFINED_METACLASS 1
62#define OOLOG_BAD_SETTING 1
63#define OOLOG_BAD_DEFAULT_SETTING 1
64#define OOLOG_BAD_POP_INDENT 1
65#define OOLOG_EXCEPTION_IN_LOG 1
80static THREAD_LOCAL
unsigned sIndentLevel = 0;
97#define OOLogInternal(cond, format, ...) \
100 OOLogInternal_(OOLOG_FUNCTION_NAME, format, ##__VA_ARGS__); \
103static void OOLogInternal_(
const char* inFunction, NSString* inFormat, ...);
114#ifndef OOLOG_NO_FILE_NAME
149 value = [sDerivedSettingsCache objectForKey:inMessageClass];
158 [sDerivedSettingsCache setObject:value forKey:inMessageClass];
161 @catch (
id exception) {
180 value = [sExplicitSettings objectForKey:inClass];
184 [sExplicitSettings setObject:CacheValue(inFlag) forKey:inClass];
201 range = [inClass rangeOfString:@"." options:NSCaseInsensitiveSearch | NSLiteralSearch | NSBackwardsSearch];
202 if (range.location == NSNotFound)
205 return [inClass substringToIndex:range.location];
208#if !OOLOG_SHORT_CIRCUIT
224#if USE_INDENT_GLOBALS
227#define INDENT_LOCK() \
230#define INDENT_UNLOCK() \
234#define INDENT_LOCK() [sLock lock]
235#define INDENT_UNLOCK() [sLock unlock]
245 sIndentLevel = value;
252 elem = malloc(
sizeof *elem);
256 elem->
indent = sIndentLevel;
257 elem->
link = sIndentStack;
271 sIndentStack = elem->
link;
272 sIndentLevel = elem->
indent;
282#define INDENT_LOCK() \
285#define INDENT_UNLOCK() \
291 NSMutableDictionary* threadDict = [[NSThread currentThread] threadDictionary];
292 return [[threadDict objectForKey:kIndentLevelKey] unsignedIntValue];
297 NSMutableDictionary* threadDict = [[NSThread currentThread] threadDictionary];
298 [threadDict setObject:[NSNumber numberWithUnsignedInt:value] forKey:kIndentLevelKey];
304 NSMutableDictionary* threadDict =
nil;
307 elem = malloc(
sizeof *elem);
309 threadDict = [[NSThread currentThread] threadDictionary];
310 val = [threadDict objectForKey:kIndentStackKey];
312 elem->
indent = [[threadDict objectForKey:kIndentLevelKey] intValue];
313 elem->
link = [val pointerValue];
319 [threadDict setObject:[NSValue valueWithPointer:elem] forKey:kIndentStackKey];
326 NSMutableDictionary* threadDict =
nil;
329 threadDict = [[NSThread currentThread] threadDictionary];
330 val = [threadDict objectForKey:kIndentStackKey];
332 elem = [val pointerValue];
335 [threadDict setObject:[NSNumber numberWithUnsignedInt:elem->indent] forKey:kIndentLevelKey];
336 [threadDict setObject:[NSValue valueWithPointer:elem->link] forKey:kIndentStackKey];
359 if (indentLevel != 0)
365void OOLogWithPrefix(NSString* inMessageClass,
const char* inFunction,
const char* inFile,
unsigned long inLine, NSString* inPrefix, NSString* inFormat, ...)
370 va_start(args, inFormat);
379 va_start(args, inFormat);
386 NSAutoreleasePool* pool =
nil;
387 NSString* formattedMessage =
nil;
388 unsigned indentLevel;
393#if !OOLOG_SHORT_CIRCUIT
398 pool = [[NSAutoreleasePool alloc] init];
401 formattedMessage = [[[NSString alloc] initWithFormat:inFormat arguments:inArguments] autorelease];
404#ifndef OOLOG_NO_FILE_NAME
407 formattedMessage = [NSString stringWithFormat:@"%s (%@:%lu): %@", inFunction, OOLogAbbreviatedFileName(inFile), inLine, formattedMessage];
409 formattedMessage = [NSString stringWithFormat:@"%@:%lu: %@", OOLogAbbreviatedFileName(inFile), inLine, formattedMessage];
415 formattedMessage = [NSString stringWithFormat:@"%s: %@", inFunction, formattedMessage];
421 formattedMessage = [NSString stringWithFormat:@"[%@] %@", inMessageClass, formattedMessage];
423 formattedMessage = [NSString stringWithFormat:@"[%@]: %@", inMessageClass, formattedMessage];
428 formattedMessage = [NSString stringWithFormat:@"%@ %@", [[NSDate date] descriptionWithCalendarFormat:@"%H:%M:%S.%F" timeZone:nil locale:nil], formattedMessage];
433 if (indentLevel != 0) {
434#define INDENT_FACTOR 2
439 const char spaces[MAX_INDENT + 1] =
" ";
440 const char* indentString;
445 indentString = &spaces[MAX_INDENT - indent];
447 formattedMessage = [NSString stringWithFormat:@"%s%@", indentString, formattedMessage];
452 @catch (NSException* exception) {
461 OOLog(
kOOLogParameterError,
@"***** %s: bad parameters. (This is an internal programming error, please report it.)", inFunction);
480 [[NSUserDefaults standardUserDefaults] setBool:flag forKey:@"logging-show-function"];
495 [[NSUserDefaults standardUserDefaults] setBool:flag forKey:@"logging-show-file-and-line"];
510 [[NSUserDefaults standardUserDefaults] setBool:flag forKey:@"logging-show-time"];
525 [[NSUserDefaults standardUserDefaults] setBool:flag forKey:@"logging-show-class"];
536 NSAutoreleasePool* pool =
nil;
541 pool = [[NSAutoreleasePool alloc] init];
543 sLock = [[NSLock alloc] init];
544 [sLock setName:@"OOLogging lock"];
548#ifndef OOLOG_NO_FILE_NAME
549 sFileNamesCache = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks, NSObjectMapValueCallBacks, 100);
583 static unsigned lastMarkerID = 0;
584 unsigned thisMarkerID;
585 NSString* marker =
nil;
588 thisMarkerID = ++lastMarkerID;
591 marker = [NSString stringWithFormat:@"\n\n========== [Marker %u] ==========", thisMarkerID];
613 NSString* formattedMessage =
nil;
614 NSAutoreleasePool* pool =
nil;
616 pool = [[NSAutoreleasePool alloc] init];
619 va_start(args, inFormat);
620 formattedMessage = [[[NSString alloc] initWithFormat:inFormat arguments:args] autorelease];
623 formattedMessage = [NSString stringWithFormat:@"OOLogging internal - %s: %@", inFunction, formattedMessage];
627 @catch (NSException* exception) {
628 fprintf(stderr,
"***** Exception in OOLogInternal_(): %s : %s", [[exception name] UTF8String], [[exception reason] UTF8String]);
653 NSUserDefaults* prefs = [NSUserDefaults standardUserDefaults];
654 sShowFunction = [prefs oo_boolForKey:@"logging-show-function" defaultValue:NO];
655 sShowFileAndLine = [prefs oo_boolForKey:@"logging-show-file-and-line" defaultValue:NO];
656 sShowTime = [prefs oo_boolForKey:@"logging-show-time" defaultValue:YES];
657 sShowClass = [prefs oo_boolForKey:@"logging-show-class" defaultValue:YES];
668 stringByAppendingPathComponent:@"logcontrol.plist"];
673 [oldSettings release];
685 id value = [sExplicitSettings objectForKey:@"_default"];
686 if (value !=
nil && [value respondsToSelector:
@selector(boolValue)]) {
694 [sExplicitSettings removeObjectForKey:@"_default"];
696 value = [sExplicitSettings objectForKey:@"_override"];
697 if (value !=
nil && [value respondsToSelector:
@selector(boolValue)]) {
707 [sExplicitSettings removeObjectForKey:@"_override"];
724 id value = [inDict objectForKey:key];
733 if ([value isKindOfClass:[NSString
class]]) {
734 if (NSOrderedSame == [value caseInsensitiveCompare:
@"yes"] || NSOrderedSame == [value caseInsensitiveCompare:
@"true"] || NSOrderedSame == [value caseInsensitiveCompare:
@"on"]) {
736 }
else if (NSOrderedSame == [value caseInsensitiveCompare:
@"no"] || NSOrderedSame == [value caseInsensitiveCompare:
@"false"] || NSOrderedSame == [value caseInsensitiveCompare:
@"off"]) {
738 }
else if (NSOrderedSame == [value caseInsensitiveCompare:
@"inherit"] || NSOrderedSame == [value caseInsensitiveCompare:
@"inherited"]) {
740 [sExplicitSettings removeObjectForKey:key];
741 }
else if (![value hasPrefix:
@"$"]) {
745 }
else if ([value respondsToSelector:
@selector(boolValue)]) {
753 [sExplicitSettings setObject:value forKey:key];
764 NSString* name =
nil;
767 return @"unspecified file";
772 name = [[NSString stringWithUTF8String:inName] lastPathComponent];
786 NSMutableSet* seenMetaClasses =
nil;
788 if (inMessageClass ==
nil)
791 value = [sExplicitSettings objectForKey:inMessageClass];
802 seenMetaClasses = [NSMutableSet set];
814 if (![inMetaClass isKindOfClass:[NSString
class]] || ![inMetaClass hasPrefix:
@"$"]) {
819 [ioSeenMetaClasses addObject:inMetaClass];
821 value = [sExplicitSettings objectForKey:inMetaClass];
#define foreachkey(VAR, DICT)
void OOLogOutputHandlerPrint(NSString *string)
void OOLogOutputHandlerClose(void)
void OOLogOutputHandlerInit(void)
NSString *const kOOLogException
NSString *const kOOLogOpenGLError
NSString *const kOOLogInconsistentState
NSString *const kOOLogDeprecatedMethod
#define OOLogOutdentIf(class)
NSString *const kOOLogFileNotLoaded
#define OOLog(class, format,...)
NSString *const kOOLogAllocationFailure
NSString *const kOOLogParameterError
NSString *const kOOLogFileNotFound
#define OOLogIndentIf(class)
NSString *const kOOLogSubclassResponsibility
static BOOL sShowFunction
void OOLogPushIndent(void)
static NSString *const kFalseToken
void OOLoggingTerminate(void)
static NSMutableDictionary * sExplicitSettings
OOINLINE unsigned GetIndentLevel(void) PURE_FUNC
OOINLINE void SetIndentLevel(unsigned level)
void OOLogPopIndent(void)
static NSString *const kTrueToken
static void LoadExplicitSettings(void)
void OOLogWithPrefix(NSString *inMessageClass, const char *inFunction, const char *inFile, unsigned long inLine, NSString *inPrefix, NSString *inFormat,...)
BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
#define OOLOG_BAD_DEFAULT_SETTING
void OOLogWithFunctionFileAndLine(NSString *inMessageClass, const char *inFunction, const char *inFile, unsigned long inLine, NSString *inFormat,...)
void OOLogSetShowFileAndLine(BOOL flag)
#define OOLOG_SETTING_RETRIEVE
void OOLogSetShowTime(BOOL flag)
void OOLogSetShowFunction(BOOL flag)
void OOLogWithFunctionFileAndLineAndArguments(NSString *inMessageClass, const char *inFunction, const char *inFile, unsigned long inLine, NSString *inFormat, va_list inArguments)
static BOOL sOverrideValue
BOOL OOLogShowFunction(void)
OOINLINE BOOL Inited(void)
static NSString *const kIndentStackKey
static BOOL sShowFileAndLine
void OOLoggingReloadSettings(void)
void OOLogGenericSubclassResponsibilityForFunction(const char *inFunction)
#define OOLOG_EXCEPTION_IN_LOG
#define OOLOG_SETTING_SET
BOOL OOLogShowMessageClass(void)
NSString * OOLogAbbreviatedFileName(const char *inName)
#define OOLogInternal(cond, format,...)
static BOOL sOverrideInEffect
static NSString *const kIndentLevelKey
void OOLogSetDisplayMessagesInClass(NSString *inClass, BOOL inFlag)
OOINLINE id CacheValue(BOOL inValue) PURE_FUNC
static void LoadExplicitSettingsFromDictionary(NSDictionary *inDict)
#define OOLOG_UNDEFINED_METACLASS
static id ResolveDisplaySetting(NSString *inMessageClass)
#define OOLOG_BAD_POP_INDENT
static void OOLogInternal_(const char *inFunction, NSString *inFormat,...)
#define OOLOG_BAD_SETTING
void OOLogInsertMarker(void)
NSString * OOLogGetParentMessageClass(NSString *inClass)
static NSString *const kInheritToken
void OOLogSetShowMessageClass(BOOL flag)
static NSMapTable * sFileNamesCache
static BOOL sDefaultDisplay
static NSMutableDictionary * sDerivedSettingsCache
static id ResolveMetaClassReference(NSString *inMetaClass, NSMutableSet *ioSeenMetaClasses)
void OOLogSetShowMessageClassTemporary(BOOL flag)
BOOL OOLogShowFileAndLine(void)
void OOLogGenericParameterErrorForFunction(const char *inFunction)
NSDictionary * OODictionaryFromFile(NSString *path)
NSDictionary * logControlDictionary()