Oolite
Loading...
Searching...
No Matches
OOLogging.m File Reference
Include dependency graph for OOLogging.m:

Go to the source code of this file.

Classes

struct  OOLogIndentStackElement

Macros

#define OOLOG_POISON_NSLOG   0
#define PER_THREAD_INDENTATION   1
#define USE_INDENT_GLOBALS   0
#define OOLOG_NOT_INITED   1
#define OOLOG_SETTING_SET   0
#define OOLOG_SETTING_RETRIEVE   0
#define OOLOG_UNDEFINED_METACLASS   1
#define OOLOG_BAD_SETTING   1
#define OOLOG_BAD_DEFAULT_SETTING   1
#define OOLOG_BAD_POP_INDENT   1
#define OOLOG_EXCEPTION_IN_LOG   1
#define OOLogInternal(cond, format, ...)
#define INDENT_LOCK()
#define INDENT_UNLOCK()
#define INDENT_FACTOR   2 /* Spaces per indent level */
#define MAX_INDENT   64 /* Maximum number of indentation _spaces_ */

Typedefs

typedef struct OOLogIndentStackElement OOLogIndentStackElement

Functions

static void OOLogInternal_ (const char *inFunction, NSString *inFormat,...)
static void LoadExplicitSettings (void)
static void LoadExplicitSettingsFromDictionary (NSDictionary *inDict)
static id ResolveDisplaySetting (NSString *inMessageClass)
static id ResolveMetaClassReference (NSString *inMetaClass, NSMutableSet *ioSeenMetaClasses)
OOINLINE unsigned GetIndentLevel (void) PURE_FUNC
OOINLINE void SetIndentLevel (unsigned level)
OOINLINE id CacheValue (BOOL inValue) PURE_FUNC
OOINLINE BOOL Inited (void)
BOOL OOLogWillDisplayMessagesInClass (NSString *inMessageClass)
void OOLogSetDisplayMessagesInClass (NSString *inClass, BOOL inFlag)
NSString * OOLogGetParentMessageClass (NSString *inClass)
void OOLogPushIndent (void)
void OOLogPopIndent (void)
void OOLogIndent (void)
void OOLogOutdent (void)
void OOLogWithPrefix (NSString *inMessageClass, const char *inFunction, const char *inFile, unsigned long inLine, NSString *inPrefix, NSString *inFormat,...)
void OOLogWithFunctionFileAndLine (NSString *inMessageClass, const char *inFunction, const char *inFile, unsigned long inLine, NSString *inFormat,...)
void OOLogWithFunctionFileAndLineAndArguments (NSString *inMessageClass, const char *inFunction, const char *inFile, unsigned long inLine, NSString *inFormat, va_list inArguments)
void OOLogGenericParameterErrorForFunction (const char *inFunction)
void OOLogGenericSubclassResponsibilityForFunction (const char *inFunction)
BOOL OOLogShowFunction (void)
void OOLogSetShowFunction (BOOL flag)
BOOL OOLogShowFileAndLine (void)
void OOLogSetShowFileAndLine (BOOL flag)
BOOL OOLogShowTime (void)
void OOLogSetShowTime (BOOL flag)
BOOL OOLogShowMessageClass (void)
void OOLogSetShowMessageClass (BOOL flag)
void OOLogSetShowMessageClassTemporary (BOOL flag)
void OOLoggingInit (void)
void OOLoggingTerminate (void)
void OOLoggingReloadSettings (void)
void OOLogInsertMarker (void)
NSString * OOLogAbbreviatedFileName (const char *inName)

Variables

static NSString *const kIndentLevelKey = @"org.aegidian.oolite.oolog.indentLevel"
static NSString *const kIndentStackKey = @"org.aegidian.oolite.oolog.indentStack"
static BOOL sInited = NO
static NSLock * sLock = nil
static NSMutableDictionary * sExplicitSettings = nil
static NSMutableDictionary * sDerivedSettingsCache = nil
static BOOL sShowFunction = NO
static BOOL sShowFileAndLine = NO
static BOOL sShowTime = NO
static BOOL sShowClass = NO
static BOOL sDefaultDisplay = YES
static BOOL sOverrideInEffect = NO
static BOOL sOverrideValue = NO
static NSString *const kTrueToken = @"on"
static NSString *const kFalseToken = @"off"
static NSString *const kInheritToken = @"inherit"
static NSMapTable * sFileNamesCache = NULL
NSString *const kOOLogSubclassResponsibility = @"general.error.subclassResponsibility"
NSString *const kOOLogParameterError = @"general.error.parameterError"
NSString *const kOOLogDeprecatedMethod = @"general.error.deprecatedMethod"
NSString *const kOOLogAllocationFailure = @"general.error.allocationFailure"
NSString *const kOOLogInconsistentState = @"general.error.inconsistentState"
NSString *const kOOLogException = @"exception"
NSString *const kOOLogFileNotFound = @"files.notFound"
NSString *const kOOLogFileNotLoaded = @"files.notLoaded"
NSString *const kOOLogOpenGLError = @"rendering.opengl.error"
NSString *const kOOLogUnconvertedNSLog = @"unclassified"

Macro Definition Documentation

◆ INDENT_FACTOR

#define INDENT_FACTOR   2 /* Spaces per indent level */

◆ INDENT_LOCK

#define INDENT_LOCK ( )
Value:
do { \
} while (0)

Definition at line 282 of file OOLogging.m.

282#define INDENT_LOCK() \
283 do { \
284 } while (0)

Referenced by OOLogIndent(), and OOLogOutdent().

◆ INDENT_UNLOCK

#define INDENT_UNLOCK ( )
Value:
do { \
} while (0)

Definition at line 285 of file OOLogging.m.

285#define INDENT_UNLOCK() \
286 do { \
287 } while (0)

Referenced by OOLogIndent(), and OOLogOutdent().

◆ MAX_INDENT

#define MAX_INDENT   64 /* Maximum number of indentation _spaces_ */

◆ OOLOG_BAD_DEFAULT_SETTING

#define OOLOG_BAD_DEFAULT_SETTING   1

Definition at line 63 of file OOLogging.m.

Referenced by LoadExplicitSettings().

◆ OOLOG_BAD_POP_INDENT

#define OOLOG_BAD_POP_INDENT   1

Definition at line 64 of file OOLogging.m.

Referenced by OOLogPopIndent().

◆ OOLOG_BAD_SETTING

#define OOLOG_BAD_SETTING   1

Definition at line 62 of file OOLogging.m.

Referenced by LoadExplicitSettingsFromDictionary(), and ResolveMetaClassReference().

◆ OOLOG_EXCEPTION_IN_LOG

#define OOLOG_EXCEPTION_IN_LOG   1

Definition at line 65 of file OOLogging.m.

Referenced by OOLogWithFunctionFileAndLineAndArguments().

◆ OOLOG_NOT_INITED

#define OOLOG_NOT_INITED   1

Definition at line 58 of file OOLogging.m.

Referenced by Inited().

◆ OOLOG_POISON_NSLOG

#define OOLOG_POISON_NSLOG   0

Definition at line 28 of file OOLogging.m.

◆ OOLOG_SETTING_RETRIEVE

#define OOLOG_SETTING_RETRIEVE   0

Definition at line 60 of file OOLogging.m.

Referenced by OOLogWillDisplayMessagesInClass().

◆ OOLOG_SETTING_SET

#define OOLOG_SETTING_SET   0

Definition at line 59 of file OOLogging.m.

Referenced by LoadExplicitSettings(), and OOLogSetDisplayMessagesInClass().

◆ OOLOG_UNDEFINED_METACLASS

#define OOLOG_UNDEFINED_METACLASS   1

Definition at line 61 of file OOLogging.m.

Referenced by ResolveMetaClassReference().

◆ OOLogInternal

#define OOLogInternal ( cond,
format,
... )
Value:
do { \
if ((cond)) { \
OOLogInternal_(OOLOG_FUNCTION_NAME, format, ##__VA_ARGS__); \
} \
} while (0)

Definition at line 97 of file OOLogging.m.

97#define OOLogInternal(cond, format, ...) \
98 do { \
99 if ((cond)) { \
100 OOLogInternal_(OOLOG_FUNCTION_NAME, format, ##__VA_ARGS__); \
101 } \
102 } while (0)

Referenced by Inited(), LoadExplicitSettings(), LoadExplicitSettingsFromDictionary(), OOLogPopIndent(), OOLogSetDisplayMessagesInClass(), OOLogWillDisplayMessagesInClass(), OOLogWithFunctionFileAndLineAndArguments(), and ResolveMetaClassReference().

◆ PER_THREAD_INDENTATION

#define PER_THREAD_INDENTATION   1

Definition at line 41 of file OOLogging.m.

◆ USE_INDENT_GLOBALS

#define USE_INDENT_GLOBALS   0

Definition at line 48 of file OOLogging.m.

Typedef Documentation

◆ OOLogIndentStackElement

typedef struct OOLogIndentStackElement OOLogIndentStackElement

Definition at line 68 of file OOLogging.m.

Function Documentation

◆ CacheValue()

OOINLINE id CacheValue ( BOOL inValue)

Definition at line 120 of file OOLogging.m.

121{
122 return inValue ? kTrueToken : kFalseToken;
123}
static NSString *const kFalseToken
Definition OOLogging.m:93
static NSString *const kTrueToken
Definition OOLogging.m:92

References kFalseToken, kTrueToken, and OOINLINE.

Referenced by LoadExplicitSettingsFromDictionary(), OOLogSetDisplayMessagesInClass(), ResolveDisplaySetting(), and ResolveMetaClassReference().

Here is the caller graph for this function:

◆ GetIndentLevel()

OOINLINE unsigned GetIndentLevel ( void )

Definition at line 289 of file OOLogging.m.

290{
291 NSMutableDictionary* threadDict = [[NSThread currentThread] threadDictionary];
292 return [[threadDict objectForKey:kIndentLevelKey] unsignedIntValue];
293}

References OOINLINE.

Referenced by OOLogIndent(), OOLogOutdent(), and OOLogWithFunctionFileAndLineAndArguments().

Here is the caller graph for this function:

◆ Inited()

OOINLINE BOOL Inited ( void )

Definition at line 128 of file OOLogging.m.

129{
130 if (EXPECT(sInited))
131 return YES;
132 OOLogInternal(OOLOG_NOT_INITED, @"***** ERROR: OOLoggingInit() has not been called.");
133 return NO;
134}
static BOOL sInited
Definition OOCPUInfo.m:56
#define EXPECT(x)
#define OOLogInternal(cond, format,...)
Definition OOLogging.m:97
#define OOLOG_NOT_INITED
Definition OOLogging.m:58

References EXPECT, OOINLINE, OOLOG_NOT_INITED, OOLogInternal, and sInited.

Referenced by OOLogSetDisplayMessagesInClass(), and OOLogWillDisplayMessagesInClass().

Here is the caller graph for this function:

◆ LoadExplicitSettings()

void LoadExplicitSettings ( void )
static

Definition at line 650 of file OOLogging.m.

651{
652 // Load display settings.
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];
658
659 NSDictionary* oldSettings = sExplicitSettings;
660
661 /*
662 HACK: we look up search paths while loading settings, which touches
663 the cache, which logs stuff. To avoid spam like dataCache.retrieve.success,
664 we first load the built-in logcontrol.plist only and use it while
665 loading the full settings.
666 */
667 NSString* path = [[[ResourceManager builtInPath] stringByAppendingPathComponent:@"Config"]
668 stringByAppendingPathComponent:@"logcontrol.plist"];
669 sExplicitSettings = [NSMutableDictionary dictionary];
671
672 // Release previous sExplicitSettings.
673 [oldSettings release];
674
675 // Load new settings.
676 NSDictionary* settings = [ResourceManager logControlDictionary];
677
678 // Replace the old dictionary.
679 sExplicitSettings = [[NSMutableDictionary alloc] init];
680
681 // Populate.
683
684 // Get _default and _override values.
685 id value = [sExplicitSettings objectForKey:@"_default"];
686 if (value != nil && [value respondsToSelector:@selector(boolValue)]) {
687 if (value == kTrueToken)
688 sDefaultDisplay = YES;
689 else if (value == kFalseToken)
690 sDefaultDisplay = NO;
691 else
692 OOLogInternal(OOLOG_BAD_DEFAULT_SETTING, @"_default may not be set to a metaclass, ignoring.");
693
694 [sExplicitSettings removeObjectForKey:@"_default"];
695 }
696 value = [sExplicitSettings objectForKey:@"_override"];
697 if (value != nil && [value respondsToSelector:@selector(boolValue)]) {
698 if (value == kTrueToken) {
699 sOverrideInEffect = YES;
700 sOverrideValue = YES;
701 } else if (value == kFalseToken) {
702 sOverrideInEffect = YES;
703 sOverrideValue = NO;
704 } else
705 OOLogInternal(OOLOG_BAD_DEFAULT_SETTING, @"_override may not be set to a metaclass, ignoring.");
706
707 [sExplicitSettings removeObjectForKey:@"_override"];
708 }
709
710 // Invalidate cache.
712
714}
#define DESTROY(x)
static BOOL sShowFunction
Definition OOLogging.m:83
static BOOL sShowClass
Definition OOLogging.m:86
static NSMutableDictionary * sExplicitSettings
Definition OOLogging.m:77
#define OOLOG_BAD_DEFAULT_SETTING
Definition OOLogging.m:63
static BOOL sShowTime
Definition OOLogging.m:85
static BOOL sOverrideValue
Definition OOLogging.m:89
static BOOL sShowFileAndLine
Definition OOLogging.m:84
#define OOLOG_SETTING_SET
Definition OOLogging.m:59
static BOOL sOverrideInEffect
Definition OOLogging.m:88
static void LoadExplicitSettingsFromDictionary(NSDictionary *inDict)
Definition OOLogging.m:719
static BOOL sDefaultDisplay
Definition OOLogging.m:87
static NSMutableDictionary * sDerivedSettingsCache
Definition OOLogging.m:78
NSDictionary * OODictionaryFromFile(NSString *path)
return nil
NSString * builtInPath()
NSDictionary * logControlDictionary()

References ResourceManager::builtInPath, DESTROY, kFalseToken, kTrueToken, LoadExplicitSettingsFromDictionary(), ResourceManager::logControlDictionary, nil, OODictionaryFromFile(), OOLOG_BAD_DEFAULT_SETTING, OOLOG_SETTING_SET, OOLogInternal, sDefaultDisplay, sDerivedSettingsCache, sExplicitSettings, sOverrideInEffect, sOverrideValue, sShowClass, sShowFileAndLine, sShowFunction, and sShowTime.

Referenced by OOLoggingInit(), and OOLoggingReloadSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadExplicitSettingsFromDictionary()

void LoadExplicitSettingsFromDictionary ( NSDictionary * inDict)
static

Definition at line 719 of file OOLogging.m.

720{
721 id key = nil;
722 foreachkey(key, inDict)
723 {
724 id value = [inDict objectForKey:key];
725
726 /* Supported values:
727 "yes", "true" or "on" -> kTrueToken
728 "no", "false" or "off" -> kFalseToken
729 "inherit" or "inherited" -> nil
730 NSNumber -> kTrueToken or kFalseToken
731 "$metaclass" -> "$metaclass"
732 */
733 if ([value isKindOfClass:[NSString class]]) {
734 if (NSOrderedSame == [value caseInsensitiveCompare:@"yes"] || NSOrderedSame == [value caseInsensitiveCompare:@"true"] || NSOrderedSame == [value caseInsensitiveCompare:@"on"]) {
735 value = kTrueToken;
736 } else if (NSOrderedSame == [value caseInsensitiveCompare:@"no"] || NSOrderedSame == [value caseInsensitiveCompare:@"false"] || NSOrderedSame == [value caseInsensitiveCompare:@"off"]) {
737 value = kFalseToken;
738 } else if (NSOrderedSame == [value caseInsensitiveCompare:@"inherit"] || NSOrderedSame == [value caseInsensitiveCompare:@"inherited"]) {
739 value = nil;
740 [sExplicitSettings removeObjectForKey:key];
741 } else if (![value hasPrefix:@"$"]) {
742 OOLogInternal(OOLOG_BAD_SETTING, @"Bad setting value \"%@\" (expected yes, no, inherit or $metaclass).", value);
743 value = nil;
744 }
745 } else if ([value respondsToSelector:@selector(boolValue)]) {
746 value = CacheValue([value boolValue]);
747 } else {
748 OOLogInternal(OOLOG_BAD_SETTING, @"Bad setting value \"%@\" (expected yes, no, inherit or $metaclass).", value);
749 value = nil;
750 }
751
752 if (value != nil) {
753 [sExplicitSettings setObject:value forKey:key];
754 }
755 }
756}
#define foreachkey(VAR, DICT)
OOINLINE id CacheValue(BOOL inValue) PURE_FUNC
Definition OOLogging.m:120
#define OOLOG_BAD_SETTING
Definition OOLogging.m:62

References CacheValue(), foreachkey, kFalseToken, kTrueToken, nil, OOLOG_BAD_SETTING, and OOLogInternal.

Referenced by LoadExplicitSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOLogAbbreviatedFileName()

NSString * OOLogAbbreviatedFileName ( const char * inName)

Definition at line 762 of file OOLogging.m.

763{
764 NSString* name = nil;
765
766 if (EXPECT_NOT(inName == NULL))
767 return @"unspecified file";
768
769 [sLock lock];
770 name = NSMapGet(sFileNamesCache, inName);
771 if (EXPECT_NOT(name == nil)) {
772 name = [[NSString stringWithUTF8String:inName] lastPathComponent];
773 NSMapInsertKnownAbsent(sFileNamesCache, inName, name);
774 }
775 [sLock unlock];
776
777 return name;
778}
#define EXPECT_NOT(x)
static NSMapTable * sFileNamesCache
Definition OOLogging.m:115

References EXPECT_NOT, nil, and sFileNamesCache.

Referenced by OOJSStopTimeLimiter_(), and OOJSUnreachable().

Here is the caller graph for this function:

◆ OOLogGenericParameterErrorForFunction()

void OOLogGenericParameterErrorForFunction ( const char * inFunction)

Definition at line 459 of file OOLogging.m.

460{
461 OOLog(kOOLogParameterError, @"***** %s: bad parameters. (This is an internal programming error, please report it.)", inFunction);
462}
#define OOLog(class, format,...)
Definition OOLogging.h:84
NSString *const kOOLogParameterError
Definition OOLogging.m:596

◆ OOLogGenericSubclassResponsibilityForFunction()

void OOLogGenericSubclassResponsibilityForFunction ( const char * inFunction)

Definition at line 464 of file OOLogging.m.

465{
466 OOLog(kOOLogSubclassResponsibility, @"***** %s is a subclass responsibility. (This is an internal programming error, please report it.)", inFunction);
467}
NSString *const kOOLogSubclassResponsibility
Definition OOLogging.m:595

◆ OOLogGetParentMessageClass()

NSString * OOLogGetParentMessageClass ( NSString * inClass)

Definition at line 194 of file OOLogging.m.

195{
196 NSRange range;
197
198 if (inClass == nil)
199 return nil;
200
201 range = [inClass rangeOfString:@"." options:NSCaseInsensitiveSearch | NSLiteralSearch | NSBackwardsSearch]; // Only NSBackwardsSearch is important, others are optimizations
202 if (range.location == NSNotFound)
203 return nil;
204
205 return [inClass substringToIndex:range.location];
206}

References nil.

Referenced by ResolveDisplaySetting().

Here is the caller graph for this function:

◆ OOLoggingInit()

void OOLoggingInit ( void )

Definition at line 534 of file OOLogging.m.

535{
536 NSAutoreleasePool* pool = nil;
537
538 if (sInited)
539 return;
540
541 pool = [[NSAutoreleasePool alloc] init];
542
543 sLock = [[NSLock alloc] init];
544 [sLock setName:@"OOLogging lock"];
545 if (sLock == nil)
546 exit(EXIT_FAILURE);
547
548#ifndef OOLOG_NO_FILE_NAME
549 sFileNamesCache = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks, NSObjectMapValueCallBacks, 100);
550#endif
551
552 sInited = YES; // Must be before OOLogOutputHandlerInit().
554
556
558
559 [pool release];
560}
void OOPrintLogHeader(void)
Definition OOLogHeader.m:57
void OOLogOutputHandlerInit(void)
static void LoadExplicitSettings(void)
Definition OOLogging.m:650
static NSLock * sLock
Definition OOLogging.m:76

References LoadExplicitSettings(), nil, OOLogOutputHandlerInit(), OOPrintLogHeader(), sFileNamesCache, sInited, and sLock.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOLoggingReloadSettings()

void OOLoggingReloadSettings ( void )

Definition at line 576 of file OOLogging.m.

577{
579}

References LoadExplicitSettings().

Here is the call graph for this function:

◆ OOLoggingTerminate()

void OOLoggingTerminate ( void )

Definition at line 562 of file OOLogging.m.

563{
564 if (!sInited)
565 return;
566
568
569 /* We do not set sInited to NO. Instead, the output handler is required
570 to be able to handle working even after being closed. Under OS X, this
571 is done by writing to stderr in this case; on other platforms, NSLog()
572 is used and OOLogOutputHandlerClose() is a no-op.
573 */
574}
void OOLogOutputHandlerClose(void)

References OOLogOutputHandlerClose(), and sInited.

Referenced by GameController::applicationShouldTerminate:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOLogIndent()

void OOLogIndent ( void )

Definition at line 345 of file OOLogging.m.

346{
347 INDENT_LOCK();
348
350
352}
OOINLINE unsigned GetIndentLevel(void) PURE_FUNC
Definition OOLogging.m:289
OOINLINE void SetIndentLevel(unsigned level)
Definition OOLogging.m:295
#define INDENT_LOCK()
Definition OOLogging.m:282
#define INDENT_UNLOCK()
Definition OOLogging.m:285

◆ OOLogInsertMarker()

void OOLogInsertMarker ( void )

Definition at line 581 of file OOLogging.m.

582{
583 static unsigned lastMarkerID = 0;
584 unsigned thisMarkerID;
585 NSString* marker = nil;
586
587 [sLock lock];
588 thisMarkerID = ++lastMarkerID;
589 [sLock unlock];
590
591 marker = [NSString stringWithFormat:@"\n\n========== [Marker %u] ==========", thisMarkerID];
593}
void OOLogOutputHandlerPrint(NSString *string)

References nil, and OOLogOutputHandlerPrint().

Here is the call graph for this function:

◆ OOLogInternal_()

void OOLogInternal_ ( const char * inFunction,
NSString * inFormat,
... )
static

Definition at line 610 of file OOLogging.m.

611{
612 va_list args;
613 NSString* formattedMessage = nil;
614 NSAutoreleasePool* pool = nil;
615
616 pool = [[NSAutoreleasePool alloc] init];
617
618 @try {
619 va_start(args, inFormat);
620 formattedMessage = [[[NSString alloc] initWithFormat:inFormat arguments:args] autorelease];
621 va_end(args);
622
623 formattedMessage = [NSString stringWithFormat:@"OOLogging internal - %s: %@", inFunction, formattedMessage];
624
625 OOLogOutputHandlerPrint(formattedMessage);
626 }
627 @catch (NSException* exception) {
628 fprintf(stderr, "***** Exception in OOLogInternal_(): %s : %s", [[exception name] UTF8String], [[exception reason] UTF8String]);
629 }
630
631 [pool release];
632}

References nil, and OOLogOutputHandlerPrint().

Here is the call graph for this function:

◆ OOLogOutdent()

void OOLogOutdent ( void )

Definition at line 354 of file OOLogging.m.

355{
356 INDENT_LOCK();
357
358 unsigned indentLevel = GetIndentLevel();
359 if (indentLevel != 0)
360 SetIndentLevel(indentLevel - 1);
361
363}

◆ OOLogPopIndent()

void OOLogPopIndent ( void )

Definition at line 323 of file OOLogging.m.

324{
325 OOLogIndentStackElement* elem = NULL;
326 NSMutableDictionary* threadDict = nil;
327 NSValue* val = nil;
328
329 threadDict = [[NSThread currentThread] threadDictionary];
330 val = [threadDict objectForKey:kIndentStackKey];
331
332 elem = [val pointerValue];
333
334 if (elem != NULL) {
335 [threadDict setObject:[NSNumber numberWithUnsignedInt:elem->indent] forKey:kIndentLevelKey];
336 [threadDict setObject:[NSValue valueWithPointer:elem->link] forKey:kIndentStackKey];
337 free(elem);
338 } else {
339 OOLogInternal(OOLOG_BAD_POP_INDENT, @"OOLogPopIndent(): state stack underflow.");
340 }
341}
#define OOLOG_BAD_POP_INDENT
Definition OOLogging.m:64

◆ OOLogPushIndent()

void OOLogPushIndent ( void )

Definition at line 301 of file OOLogging.m.

302{
303 OOLogIndentStackElement* elem = NULL;
304 NSMutableDictionary* threadDict = nil;
305 NSValue* val = nil;
306
307 elem = malloc(sizeof *elem);
308 if (elem != NULL) {
309 threadDict = [[NSThread currentThread] threadDictionary];
310 val = [threadDict objectForKey:kIndentStackKey];
311
312 elem->indent = [[threadDict objectForKey:kIndentLevelKey] intValue];
313 elem->link = [val pointerValue];
314
315 /*
316 Clang static analyzer reports elem not released here. It is in fact
317 released in OOLogPopIndent().
318 */
319 [threadDict setObject:[NSValue valueWithPointer:elem] forKey:kIndentStackKey];
320 }
321}
OOLogIndentStackElement * link
Definition OOLogging.m:70

◆ OOLogSetDisplayMessagesInClass()

void OOLogSetDisplayMessagesInClass ( NSString * inClass,
BOOL inFlag )

Definition at line 172 of file OOLogging.m.

173{
174 id value = nil;
175
176 if (!Inited())
177 return;
178
179 [sLock lock];
180 value = [sExplicitSettings objectForKey:inClass];
181 if (value == nil || value != CacheValue(inFlag)) {
182 OOLogInternal(OOLOG_SETTING_SET, @"Setting %@ to %s", inClass, inFlag ? "ON" : "OFF");
183
184 [sExplicitSettings setObject:CacheValue(inFlag) forKey:inClass];
185
186 // Clear cache and let it be rebuilt as needed.
188 } else {
189 OOLogInternal(OOLOG_SETTING_SET, @"Keeping %@ %s", inClass, inFlag ? "ON" : "OFF");
190 }
191 [sLock unlock];
192}
OOINLINE BOOL Inited(void)
Definition OOLogging.m:128

References CacheValue(), DESTROY, Inited(), nil, OOLOG_SETTING_SET, OOLogInternal, and sDerivedSettingsCache.

Referenced by PlayerEntity(Scripting)::debugOff, PlayerEntity(Scripting)::debugOn, GameController::endSplashScreen, OOPListSchemaVerifier::initWithSchema:, PlayerEntity(OOControlsPrivate)::pollFlightControls:, and OOOXPVerifier(OOPrivate)::setUpLogOverrides.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOLogSetShowFileAndLine()

void OOLogSetShowFileAndLine ( BOOL flag)

Definition at line 489 of file OOLogging.m.

490{
491 flag = !!flag; // YES or NO, not 42.
492
493 if (flag != sShowFileAndLine) {
494 sShowFileAndLine = flag;
495 [[NSUserDefaults standardUserDefaults] setBool:flag forKey:@"logging-show-file-and-line"];
496 }
497}

References sShowFileAndLine.

◆ OOLogSetShowFunction()

void OOLogSetShowFunction ( BOOL flag)

Definition at line 474 of file OOLogging.m.

475{
476 flag = !!flag; // YES or NO, not 42.
477
478 if (flag != sShowFunction) {
479 sShowFunction = flag;
480 [[NSUserDefaults standardUserDefaults] setBool:flag forKey:@"logging-show-function"];
481 }
482}

References sShowFunction.

◆ OOLogSetShowMessageClass()

void OOLogSetShowMessageClass ( BOOL flag)

Definition at line 519 of file OOLogging.m.

520{
521 flag = !!flag; // YES or NO, not 42.
522
523 if (flag != sShowClass) {
524 sShowClass = flag;
525 [[NSUserDefaults standardUserDefaults] setBool:flag forKey:@"logging-show-class"];
526 }
527}

References sShowClass.

◆ OOLogSetShowMessageClassTemporary()

void OOLogSetShowMessageClassTemporary ( BOOL flag)

Definition at line 529 of file OOLogging.m.

530{
531 sShowClass = !!flag; // YES or NO, not 42.
532}

References sShowClass.

Referenced by OOOXPVerifier(OOPrivate)::setUpLogOverrides.

Here is the caller graph for this function:

◆ OOLogSetShowTime()

void OOLogSetShowTime ( BOOL flag)

Definition at line 504 of file OOLogging.m.

505{
506 flag = !!flag; // YES or NO, not 42.
507
508 if (flag != sShowTime) {
509 sShowTime = flag;
510 [[NSUserDefaults standardUserDefaults] setBool:flag forKey:@"logging-show-time"];
511 }
512}

References sShowTime.

◆ OOLogShowFileAndLine()

BOOL OOLogShowFileAndLine ( void )

Definition at line 484 of file OOLogging.m.

485{
486 return sShowFileAndLine;
487}

References sShowFileAndLine.

◆ OOLogShowFunction()

BOOL OOLogShowFunction ( void )

Definition at line 469 of file OOLogging.m.

470{
471 return sShowFunction;
472}

References sShowFunction.

◆ OOLogShowMessageClass()

BOOL OOLogShowMessageClass ( void )

Definition at line 514 of file OOLogging.m.

515{
516 return sShowClass;
517}

References sShowClass.

◆ OOLogShowTime()

BOOL OOLogShowTime ( void )

Definition at line 499 of file OOLogging.m.

500{
501 return sShowTime;
502}

References sShowTime.

◆ OOLogWillDisplayMessagesInClass()

BOOL OOLogWillDisplayMessagesInClass ( NSString * inMessageClass)

Definition at line 136 of file OOLogging.m.

137{
138 id value = nil;
139
140 if (!Inited())
141 return NO;
142
144 return sOverrideValue;
145
146 [sLock lock];
147
148 // Look for cached value
149 value = [sDerivedSettingsCache objectForKey:inMessageClass];
150 if (EXPECT_NOT(value == nil)) {
151 @try {
152 // No cached value.
153 value = ResolveDisplaySetting(inMessageClass);
154
155 if (value != nil) {
157 sDerivedSettingsCache = [[NSMutableDictionary alloc] init];
158 [sDerivedSettingsCache setObject:value forKey:inMessageClass];
159 }
160 }
161 @catch (id exception) {
162 [sLock unlock];
163 @throw exception;
164 }
165 }
166 [sLock unlock];
167
168 OOLogInternal(OOLOG_SETTING_RETRIEVE, @"%@ is %s", inMessageClass, (value == kTrueToken) ? "on" : "off");
169 return value == kTrueToken;
170}
#define OOLOG_SETTING_RETRIEVE
Definition OOLogging.m:60
static id ResolveDisplaySetting(NSString *inMessageClass)
Definition OOLogging.m:783

Referenced by OOLogWithFunctionFileAndLineAndArguments(), and OOLogWithPrefix().

Here is the caller graph for this function:

◆ OOLogWithFunctionFileAndLine()

void OOLogWithFunctionFileAndLine ( NSString * inMessageClass,
const char * inFunction,
const char * inFile,
unsigned long inLine,
NSString * inFormat,
... )

Definition at line 375 of file OOLogging.m.

376{
377 va_list args;
378
379 va_start(args, inFormat);
380 OOLogWithFunctionFileAndLineAndArguments(inMessageClass, inFunction, inFile, inLine, inFormat, args);
381 va_end(args);
382}
void OOLogWithFunctionFileAndLineAndArguments(NSString *inMessageClass, const char *inFunction, const char *inFile, unsigned long inLine, NSString *inFormat, va_list inArguments)
Definition OOLogging.m:384

References OOLogWithFunctionFileAndLineAndArguments().

Here is the call graph for this function:

◆ OOLogWithFunctionFileAndLineAndArguments()

void OOLogWithFunctionFileAndLineAndArguments ( NSString * inMessageClass,
const char * inFunction,
const char * inFile,
unsigned long inLine,
NSString * inFormat,
va_list inArguments )

Definition at line 384 of file OOLogging.m.

385{
386 NSAutoreleasePool* pool = nil;
387 NSString* formattedMessage = nil;
388 unsigned indentLevel;
389
390 if (inFormat == nil)
391 return;
392
393#if !OOLOG_SHORT_CIRCUIT
394 if (!OOLogWillDisplayMessagesInClass(inMessageClass))
395 return;
396#endif
397
398 pool = [[NSAutoreleasePool alloc] init];
399 @try {
400 // Do argument substitution
401 formattedMessage = [[[NSString alloc] initWithFormat:inFormat arguments:inArguments] autorelease];
402
403 // Apply various prefix options
404#ifndef OOLOG_NO_FILE_NAME
405 if (sShowFileAndLine && inFile != NULL) {
406 if (sShowFunction) {
407 formattedMessage = [NSString stringWithFormat:@"%s (%@:%lu): %@", inFunction, OOLogAbbreviatedFileName(inFile), inLine, formattedMessage];
408 } else {
409 formattedMessage = [NSString stringWithFormat:@"%@:%lu: %@", OOLogAbbreviatedFileName(inFile), inLine, formattedMessage];
410 }
411 } else
412#endif
413 {
414 if (sShowFunction) {
415 formattedMessage = [NSString stringWithFormat:@"%s: %@", inFunction, formattedMessage];
416 }
417 }
418
419 if (sShowClass) {
421 formattedMessage = [NSString stringWithFormat:@"[%@] %@", inMessageClass, formattedMessage];
422 } else {
423 formattedMessage = [NSString stringWithFormat:@"[%@]: %@", inMessageClass, formattedMessage];
424 }
425 }
426
427 if (sShowTime) {
428 formattedMessage = [NSString stringWithFormat:@"%@ %@", [[NSDate date] descriptionWithCalendarFormat:@"%H:%M:%S.%F" timeZone:nil locale:nil], formattedMessage];
429 }
430
431 // Apply indentation
432 indentLevel = GetIndentLevel();
433 if (indentLevel != 0) {
434#define INDENT_FACTOR 2 /* Spaces per indent level */
435#define MAX_INDENT 64 /* Maximum number of indentation _spaces_ */
436
437 unsigned indent;
438 // String of 64 spaces (null-terminated)
439 const char spaces[MAX_INDENT + 1] = " ";
440 const char* indentString;
441
442 indent = INDENT_FACTOR * indentLevel;
443 if (MAX_INDENT < indent)
444 indent = MAX_INDENT;
445 indentString = &spaces[MAX_INDENT - indent];
446
447 formattedMessage = [NSString stringWithFormat:@"%s%@", indentString, formattedMessage];
448 }
449
450 OOLogOutputHandlerPrint(formattedMessage);
451 }
452 @catch (NSException* exception) {
453 OOLogInternal(OOLOG_EXCEPTION_IN_LOG, @"***** Exception thrown during logging: %@ : %@", [exception name], [exception reason]);
454 }
455
456 [pool release];
457}
BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
Definition OOLogging.m:136
#define OOLOG_EXCEPTION_IN_LOG
Definition OOLogging.m:65
#define MAX_INDENT
#define INDENT_FACTOR

References GetIndentLevel(), INDENT_FACTOR, MAX_INDENT, nil, OOLOG_EXCEPTION_IN_LOG, OOLogInternal, OOLogOutputHandlerPrint(), OOLogWillDisplayMessagesInClass(), sShowClass, sShowFileAndLine, sShowFunction, and sShowTime.

Referenced by OOLogWithFunctionFileAndLine(), and OOLogWithPrefix().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOLogWithPrefix()

void OOLogWithPrefix ( NSString * inMessageClass,
const char * inFunction,
const char * inFile,
unsigned long inLine,
NSString * inPrefix,
NSString * inFormat,
... )

Definition at line 365 of file OOLogging.m.

366{
367 if (!OOLogWillDisplayMessagesInClass(inMessageClass))
368 return;
369 va_list args;
370 va_start(args, inFormat);
371 OOLogWithFunctionFileAndLineAndArguments(inMessageClass, inFunction, inFile, inLine, [inPrefix stringByAppendingString:inFormat], args);
372 va_end(args);
373}

References OOLogWillDisplayMessagesInClass(), and OOLogWithFunctionFileAndLineAndArguments().

Here is the call graph for this function:

◆ ResolveDisplaySetting()

id ResolveDisplaySetting ( NSString * inMessageClass)
static

Definition at line 783 of file OOLogging.m.

784{
785 id value = nil;
786 NSMutableSet* seenMetaClasses = nil;
787
788 if (inMessageClass == nil)
790
791 value = [sExplicitSettings objectForKey:inMessageClass];
792
793 // Simple case: explicit setting for this value
794 if (value == kTrueToken || value == kFalseToken)
795 return value;
796
797 // Simplish case: use inherited value
798 if (value == nil || value == kInheritToken)
800
801 // Less simple case: should be a metaclass.
802 seenMetaClasses = [NSMutableSet set];
803 return ResolveMetaClassReference(value, seenMetaClasses);
804}
NSString * OOLogGetParentMessageClass(NSString *inClass)
Definition OOLogging.m:194
static NSString *const kInheritToken
Definition OOLogging.m:94
static id ResolveMetaClassReference(NSString *inMetaClass, NSMutableSet *ioSeenMetaClasses)
Definition OOLogging.m:809

References CacheValue(), kFalseToken, kInheritToken, kTrueToken, nil, OOLogGetParentMessageClass(), ResolveDisplaySetting(), ResolveMetaClassReference(), and sDefaultDisplay.

Referenced by OOLogWillDisplayMessagesInClass(), and ResolveDisplaySetting().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResolveMetaClassReference()

id ResolveMetaClassReference ( NSString * inMetaClass,
NSMutableSet * ioSeenMetaClasses )
static

Definition at line 809 of file OOLogging.m.

810{
811 id value = nil;
812
813 // All values should have been checked at load time, but what the hey.
814 if (![inMetaClass isKindOfClass:[NSString class]] || ![inMetaClass hasPrefix:@"$"]) {
815 OOLogInternal(OOLOG_BAD_SETTING, @"Bad setting value \"%@\" (expected yes, no, inherit or $metaclass). Falling back to _default.", inMetaClass);
817 }
818
819 [ioSeenMetaClasses addObject:inMetaClass];
820
821 value = [sExplicitSettings objectForKey:inMetaClass];
822
823 if (value == kTrueToken || value == kFalseToken)
824 return value;
825 if (value == nil) {
826 OOLogInternal(OOLOG_UNDEFINED_METACLASS, @"Reference to undefined metaclass %@, falling back to _default.", inMetaClass);
828 }
829
830 // If we get here, it should be a metaclass reference.
831 return ResolveMetaClassReference(value, ioSeenMetaClasses);
832}
#define OOLOG_UNDEFINED_METACLASS
Definition OOLogging.m:61

References CacheValue(), kFalseToken, kTrueToken, nil, OOLOG_BAD_SETTING, OOLOG_UNDEFINED_METACLASS, OOLogInternal, ResolveMetaClassReference(), and sDefaultDisplay.

Referenced by ResolveDisplaySetting(), and ResolveMetaClassReference().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetIndentLevel()

OOINLINE void SetIndentLevel ( unsigned level)

Definition at line 295 of file OOLogging.m.

296{
297 NSMutableDictionary* threadDict = [[NSThread currentThread] threadDictionary];
298 [threadDict setObject:[NSNumber numberWithUnsignedInt:value] forKey:kIndentLevelKey];
299}

References OOINLINE.

Referenced by OOLogIndent(), and OOLogOutdent().

Here is the caller graph for this function:

Variable Documentation

◆ kFalseToken

NSString* const kFalseToken = @"off"
static

◆ kIndentLevelKey

NSString* const kIndentLevelKey = @"org.aegidian.oolite.oolog.indentLevel"
static

Definition at line 49 of file OOLogging.m.

◆ kIndentStackKey

NSString* const kIndentStackKey = @"org.aegidian.oolite.oolog.indentStack"
static

Definition at line 50 of file OOLogging.m.

◆ kInheritToken

NSString* const kInheritToken = @"inherit"
static

Definition at line 94 of file OOLogging.m.

Referenced by ResolveDisplaySetting().

◆ kOOLogAllocationFailure

NSString* const kOOLogAllocationFailure = @"general.error.allocationFailure"

Definition at line 598 of file OOLogging.m.

◆ kOOLogDeprecatedMethod

NSString* const kOOLogDeprecatedMethod = @"general.error.deprecatedMethod"

Definition at line 597 of file OOLogging.m.

◆ kOOLogException

NSString* const kOOLogException = @"exception"

Definition at line 600 of file OOLogging.m.

◆ kOOLogFileNotFound

NSString* const kOOLogFileNotFound = @"files.notFound"

Definition at line 601 of file OOLogging.m.

◆ kOOLogFileNotLoaded

NSString* const kOOLogFileNotLoaded = @"files.notLoaded"

Definition at line 602 of file OOLogging.m.

◆ kOOLogInconsistentState

NSString* const kOOLogInconsistentState = @"general.error.inconsistentState"

Definition at line 599 of file OOLogging.m.

◆ kOOLogOpenGLError

NSString* const kOOLogOpenGLError = @"rendering.opengl.error"

Definition at line 603 of file OOLogging.m.

◆ kOOLogParameterError

NSString* const kOOLogParameterError = @"general.error.parameterError"

Definition at line 596 of file OOLogging.m.

◆ kOOLogSubclassResponsibility

NSString* const kOOLogSubclassResponsibility = @"general.error.subclassResponsibility"

Definition at line 595 of file OOLogging.m.

◆ kOOLogUnconvertedNSLog

NSString* const kOOLogUnconvertedNSLog = @"unclassified"

Definition at line 604 of file OOLogging.m.

◆ kTrueToken

◆ sDefaultDisplay

BOOL sDefaultDisplay = YES
static

◆ sDerivedSettingsCache

NSMutableDictionary* sDerivedSettingsCache = nil
static

◆ sExplicitSettings

NSMutableDictionary* sExplicitSettings = nil
static

Definition at line 77 of file OOLogging.m.

Referenced by LoadExplicitSettings().

◆ sFileNamesCache

NSMapTable* sFileNamesCache = NULL
static

Definition at line 115 of file OOLogging.m.

Referenced by OOLogAbbreviatedFileName(), and OOLoggingInit().

◆ sInited

BOOL sInited = NO
static

Definition at line 75 of file OOLogging.m.

◆ sLock

NSLock* sLock = nil
static

Definition at line 76 of file OOLogging.m.

Referenced by OOLoggingInit().

◆ sOverrideInEffect

BOOL sOverrideInEffect = NO
static

Definition at line 88 of file OOLogging.m.

Referenced by LoadExplicitSettings(), and OOLogWillDisplayMessagesInClass().

◆ sOverrideValue

BOOL sOverrideValue = NO
static

Definition at line 89 of file OOLogging.m.

Referenced by LoadExplicitSettings(), and OOLogWillDisplayMessagesInClass().

◆ sShowClass

◆ sShowFileAndLine

BOOL sShowFileAndLine = NO
static

◆ sShowFunction

BOOL sShowFunction = NO
static

◆ sShowTime

BOOL sShowTime = NO
static