Oolite 1.91.0.7646-241128-10e222e
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 298 of file OOLogging.m.

Referenced by OOLogIndent(), and OOLogOutdent().

◆ INDENT_UNLOCK

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

Definition at line 299 of file OOLogging.m.

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 67 of file OOLogging.m.

Referenced by LoadExplicitSettings().

◆ OOLOG_BAD_POP_INDENT

#define OOLOG_BAD_POP_INDENT   1

Definition at line 68 of file OOLogging.m.

Referenced by OOLogPopIndent().

◆ OOLOG_BAD_SETTING

#define OOLOG_BAD_SETTING   1

Definition at line 66 of file OOLogging.m.

Referenced by LoadExplicitSettingsFromDictionary(), and ResolveMetaClassReference().

◆ OOLOG_EXCEPTION_IN_LOG

#define OOLOG_EXCEPTION_IN_LOG   1

Definition at line 69 of file OOLogging.m.

Referenced by OOLogWithFunctionFileAndLineAndArguments().

◆ OOLOG_NOT_INITED

#define OOLOG_NOT_INITED   1

Definition at line 62 of file OOLogging.m.

Referenced by Inited().

◆ OOLOG_POISON_NSLOG

#define OOLOG_POISON_NSLOG   0

Definition at line 29 of file OOLogging.m.

◆ OOLOG_SETTING_RETRIEVE

#define OOLOG_SETTING_RETRIEVE   0

Definition at line 64 of file OOLogging.m.

Referenced by OOLogWillDisplayMessagesInClass().

◆ OOLOG_SETTING_SET

#define OOLOG_SETTING_SET   0

Definition at line 63 of file OOLogging.m.

Referenced by LoadExplicitSettings(), and OOLogSetDisplayMessagesInClass().

◆ OOLOG_UNDEFINED_METACLASS

#define OOLOG_UNDEFINED_METACLASS   1

Definition at line 65 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)
static void OOLogInternal_(const char *inFunction, NSString *inFormat,...)
Definition OOLogging.m:662

Definition at line 106 of file OOLogging.m.

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

◆ PER_THREAD_INDENTATION

#define PER_THREAD_INDENTATION   1

Definition at line 43 of file OOLogging.m.

◆ USE_INDENT_GLOBALS

#define USE_INDENT_GLOBALS   0

Definition at line 51 of file OOLogging.m.

Typedef Documentation

◆ OOLogIndentStackElement

typedef struct OOLogIndentStackElement OOLogIndentStackElement

Definition at line 73 of file OOLogging.m.

Function Documentation

◆ CacheValue()

OOINLINE id CacheValue ( BOOL inValue)

Definition at line 127 of file OOLogging.m.

128{
129 return inValue ? kTrueToken : kFalseToken;
130}
static NSString *const kFalseToken
Definition OOLogging.m:101
static NSString *const kTrueToken
Definition OOLogging.m:100

References kFalseToken, and kTrueToken.

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

+ Here is the caller graph for this function:

◆ GetIndentLevel()

OOINLINE unsigned GetIndentLevel ( void )

Definition at line 302 of file OOLogging.m.

303{
304 NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary];
305 return [[threadDict objectForKey:kIndentLevelKey] unsignedIntValue];
306}

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

+ Here is the caller graph for this function:

◆ Inited()

OOINLINE BOOL Inited ( void )

Definition at line 136 of file OOLogging.m.

137{
138 if (EXPECT(sInited)) return YES;
139 OOLogInternal(OOLOG_NOT_INITED, @"***** ERROR: OOLoggingInit() has not been called.");
140 return NO;
141}
#define EXPECT(x)
#define OOLogInternal(cond, format,...)
Definition OOLogging.m:106
static BOOL sInited
Definition OOLogging.m:82
#define OOLOG_NOT_INITED
Definition OOLogging.m:62

References EXPECT, OOLOG_NOT_INITED, OOLogInternal, and sInited.

Referenced by OOLogSetDisplayMessagesInClass(), and OOLogWillDisplayMessagesInClass().

+ Here is the caller graph for this function:

◆ LoadExplicitSettings()

static void LoadExplicitSettings ( void )
static

Definition at line 705 of file OOLogging.m.

706{
707 // Load display settings.
708 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
709 sShowFunction = [prefs oo_boolForKey:@"logging-show-function" defaultValue:NO];
710 sShowFileAndLine = [prefs oo_boolForKey:@"logging-show-file-and-line" defaultValue:NO];
711 sShowTime = [prefs oo_boolForKey:@"logging-show-time" defaultValue:YES];
712 sShowClass = [prefs oo_boolForKey:@"logging-show-class" defaultValue:YES];
713
714 NSDictionary *oldSettings = sExplicitSettings;
715
716 /*
717 HACK: we look up search paths while loading settings, which touches
718 the cache, which logs stuff. To avoid spam like dataCache.retrieve.success,
719 we first load the built-in logcontrol.plist only and use it while
720 loading the full settings.
721 */
722 NSString *path = [[[ResourceManager builtInPath] stringByAppendingPathComponent:@"Config"]
723 stringByAppendingPathComponent:@"logcontrol.plist"];
724 sExplicitSettings = [NSMutableDictionary dictionary];
726
727 // Release previous sExplicitSettings.
728 [oldSettings release];
729
730 // Load new settings.
731 NSDictionary *settings = [ResourceManager logControlDictionary];
732
733 // Replace the old dictionary.
734 sExplicitSettings = [[NSMutableDictionary alloc] init];
735
736 // Populate.
738
739 // Get _default and _override values.
740 id value = [sExplicitSettings objectForKey:@"_default"];
741 if (value != nil && [value respondsToSelector:@selector(boolValue)])
742 {
743 if (value == kTrueToken) sDefaultDisplay = YES;
744 else if (value == kFalseToken) sDefaultDisplay = NO;
745 else OOLogInternal(OOLOG_BAD_DEFAULT_SETTING, @"_default may not be set to a metaclass, ignoring.");
746
747 [sExplicitSettings removeObjectForKey:@"_default"];
748 }
749 value = [sExplicitSettings objectForKey:@"_override"];
750 if (value != nil && [value respondsToSelector:@selector(boolValue)])
751 {
752 if (value == kTrueToken)
753 {
754 sOverrideInEffect = YES;
755 sOverrideValue = YES;
756 }
757 else if (value == kFalseToken)
758 {
759 sOverrideInEffect = YES;
760 sOverrideValue = NO;
761 }
762 else OOLogInternal(OOLOG_BAD_DEFAULT_SETTING, @"_override may not be set to a metaclass, ignoring.");
763
764 [sExplicitSettings removeObjectForKey:@"_override"];
765 }
766
767 // Invalidate cache.
769
771}
#define DESTROY(x)
Definition OOCocoa.h:77
static BOOL sShowFunction
Definition OOLogging.m:91
static BOOL sShowClass
Definition OOLogging.m:94
static NSMutableDictionary * sExplicitSettings
Definition OOLogging.m:84
#define OOLOG_BAD_DEFAULT_SETTING
Definition OOLogging.m:67
static BOOL sShowTime
Definition OOLogging.m:93
static BOOL sOverrideValue
Definition OOLogging.m:97
static BOOL sShowFileAndLine
Definition OOLogging.m:92
#define OOLOG_SETTING_SET
Definition OOLogging.m:63
static BOOL sOverrideInEffect
Definition OOLogging.m:96
static void LoadExplicitSettingsFromDictionary(NSDictionary *inDict)
Definition OOLogging.m:777
static BOOL sDefaultDisplay
Definition OOLogging.m:95
static NSMutableDictionary * sDerivedSettingsCache
Definition OOLogging.m:85
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()

static void LoadExplicitSettingsFromDictionary ( NSDictionary * inDict)
static

Definition at line 777 of file OOLogging.m.

778{
779 id key = nil;
780 foreachkey (key, inDict)
781 {
782 id value = [inDict objectForKey:key];
783
784 /* Supported values:
785 "yes", "true" or "on" -> kTrueToken
786 "no", "false" or "off" -> kFalseToken
787 "inherit" or "inherited" -> nil
788 NSNumber -> kTrueToken or kFalseToken
789 "$metaclass" -> "$metaclass"
790 */
791 if ([value isKindOfClass:[NSString class]])
792 {
793 if (NSOrderedSame == [value caseInsensitiveCompare:@"yes"] ||
794 NSOrderedSame == [value caseInsensitiveCompare:@"true"] ||
795 NSOrderedSame == [value caseInsensitiveCompare:@"on"])
796 {
797 value = kTrueToken;
798 }
799 else if (NSOrderedSame == [value caseInsensitiveCompare:@"no"] ||
800 NSOrderedSame == [value caseInsensitiveCompare:@"false"] ||
801 NSOrderedSame == [value caseInsensitiveCompare:@"off"])
802 {
803 value = kFalseToken;
804 }
805 else if (NSOrderedSame == [value caseInsensitiveCompare:@"inherit"] ||
806 NSOrderedSame == [value caseInsensitiveCompare:@"inherited"])
807 {
808 value = nil;
809 [sExplicitSettings removeObjectForKey:key];
810 }
811 else if (![value hasPrefix:@"$"])
812 {
813 OOLogInternal(OOLOG_BAD_SETTING, @"Bad setting value \"%@\" (expected yes, no, inherit or $metaclass).", value);
814 value = nil;
815 }
816 }
817 else if ([value respondsToSelector:@selector(boolValue)])
818 {
819 value = CacheValue([value boolValue]);
820 }
821 else
822 {
823 OOLogInternal(OOLOG_BAD_SETTING, @"Bad setting value \"%@\" (expected yes, no, inherit or $metaclass).", value);
824 value = nil;
825 }
826
827 if (value != nil)
828 {
829 [sExplicitSettings setObject:value forKey:key];
830 }
831 }
832}
#define foreachkey(VAR, DICT)
Definition OOCocoa.h:366
OOINLINE id CacheValue(BOOL inValue) PURE_FUNC
Definition OOLogging.m:127
#define OOLOG_BAD_SETTING
Definition OOLogging.m:66

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 839 of file OOLogging.m.

840{
841 NSString *name = nil;
842
843 if (EXPECT_NOT(inName == NULL)) return @"unspecified file";
844
845 [sLock lock];
846 name = NSMapGet(sFileNamesCache, inName);
847 if (EXPECT_NOT(name == nil))
848 {
849 name = [[NSString stringWithUTF8String:inName] lastPathComponent];
850 NSMapInsertKnownAbsent(sFileNamesCache, inName, name);
851 }
852 [sLock unlock];
853
854 return name;
855}
#define EXPECT_NOT(x)
static NSMapTable * sFileNamesCache
Definition OOLogging.m:121

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 495 of file OOLogging.m.

496{
497 OOLog(kOOLogParameterError, @"***** %s: bad parameters. (This is an internal programming error, please report it.)", inFunction);
498}
#define OOLog(class, format,...)
Definition OOLogging.h:88
NSString *const kOOLogParameterError
Definition OOLogging.m:647

References kOOLogParameterError, and OOLog.

◆ OOLogGenericSubclassResponsibilityForFunction()

void OOLogGenericSubclassResponsibilityForFunction ( const char * inFunction)

Definition at line 501 of file OOLogging.m.

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

References kOOLogSubclassResponsibility, and OOLog.

◆ OOLogGetParentMessageClass()

NSString * OOLogGetParentMessageClass ( NSString * inClass)

Definition at line 207 of file OOLogging.m.

208{
209 NSRange range;
210
211 if (inClass == nil) return nil;
212
213 range = [inClass rangeOfString:@"." options:NSCaseInsensitiveSearch | NSLiteralSearch | NSBackwardsSearch]; // Only NSBackwardsSearch is important, others are optimizations
214 if (range.location == NSNotFound) return nil;
215
216 return [inClass substringToIndex:range.location];
217}

References nil.

Referenced by ResolveDisplaySetting().

+ Here is the caller graph for this function:

◆ OOLoggingInit()

void OOLoggingInit ( void )

Definition at line 585 of file OOLogging.m.

586{
587 NSAutoreleasePool *pool = nil;
588
589 if (sInited) return;
590
591 pool = [[NSAutoreleasePool alloc] init];
592
593 sLock = [[NSLock alloc] init];
594 [sLock setName:@"OOLogging lock"];
595 if (sLock == nil) exit(EXIT_FAILURE);
596
597#ifndef OOLOG_NO_FILE_NAME
598 sFileNamesCache = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks, NSObjectMapValueCallBacks, 100);
599#endif
600
601 sInited = YES; // Must be before OOLogOutputHandlerInit().
603
605
607
608 [pool release];
609}
void OOPrintLogHeader(void)
Definition OOLogHeader.m:60
void OOLogOutputHandlerInit(void)
static void LoadExplicitSettings(void)
Definition OOLogging.m:705
static NSLock * sLock
Definition OOLogging.m:83

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

Referenced by main(), and main().

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

◆ OOLoggingReloadSettings()

void OOLoggingReloadSettings ( void )

Definition at line 626 of file OOLogging.m.

627{
629}

References LoadExplicitSettings().

+ Here is the call graph for this function:

◆ OOLoggingTerminate()

void OOLoggingTerminate ( void )

Definition at line 612 of file OOLogging.m.

613{
614 if (!sInited) return;
615
617
618 /* We do not set sInited to NO. Instead, the output handler is required
619 to be able to handle working even after being closed. Under OS X, this
620 is done by writing to stderr in this case; on other platforms, NSLog()
621 is used and OOLogOutputHandlerClose() is a no-op.
622 */
623}
void OOLogOutputHandlerClose(void)

References OOLogOutputHandlerClose(), and sInited.

+ Here is the call graph for this function:

◆ OOLogIndent()

void OOLogIndent ( void )

Definition at line 366 of file OOLogging.m.

367{
368 INDENT_LOCK();
369
371
373}
OOINLINE unsigned GetIndentLevel(void) PURE_FUNC
Definition OOLogging.m:302
OOINLINE void SetIndentLevel(unsigned level)
Definition OOLogging.m:309
#define INDENT_LOCK()
Definition OOLogging.m:298
#define INDENT_UNLOCK()
Definition OOLogging.m:299

References GetIndentLevel(), INDENT_LOCK, INDENT_UNLOCK, and SetIndentLevel().

Referenced by GLDumpCullingState(), GLDumpFogState(), GLDumpLightState(), GLDumpMaterialState(), GLDumpStateFlags(), LogOpenGLState(), OOCheckOpenGLErrors(), OOJSBeginProfiling(), OOJSProfileEnter(), and VerifyOpenGLStateInternal().

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

◆ OOLogInsertMarker()

void OOLogInsertMarker ( void )

Definition at line 632 of file OOLogging.m.

633{
634 static unsigned lastMarkerID = 0;
635 unsigned thisMarkerID;
636 NSString *marker = nil;
637
638 [sLock lock];
639 thisMarkerID = ++lastMarkerID;
640 [sLock unlock];
641
642 marker = [NSString stringWithFormat:@"\n\n========== [Marker %u] ==========", thisMarkerID];
644}
void OOLogOutputHandlerPrint(NSString *string)

References nil, and OOLogOutputHandlerPrint().

Referenced by ConsoleWriteLogMarker().

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

◆ OOLogInternal_()

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

Definition at line 662 of file OOLogging.m.

663{
664 va_list args;
665 NSString *formattedMessage = nil;
666 NSAutoreleasePool *pool = nil;
667
668 pool = [[NSAutoreleasePool alloc] init];
669
670 @try
671 {
672 va_start(args, inFormat);
673 formattedMessage = [[[NSString alloc] initWithFormat:inFormat arguments:args] autorelease];
674 va_end(args);
675
676 formattedMessage = [NSString stringWithFormat:@"OOLogging internal - %s: %@", inFunction, formattedMessage];
677
678 OOLogOutputHandlerPrint(formattedMessage);
679 }
680 @catch (NSException *exception)
681 {
682 fprintf(stderr, "***** Exception in OOLogInternal_(): %s : %s", [[exception name] UTF8String], [[exception reason] UTF8String]);
683 }
684
685 [pool release];
686}

References nil, and OOLogOutputHandlerPrint().

+ Here is the call graph for this function:

◆ OOLogOutdent()

void OOLogOutdent ( void )

Definition at line 376 of file OOLogging.m.

377{
378 INDENT_LOCK();
379
380 unsigned indentLevel = GetIndentLevel();
381 if (indentLevel != 0) SetIndentLevel(indentLevel - 1);
382
384}

References GetIndentLevel(), INDENT_LOCK, INDENT_UNLOCK, and SetIndentLevel().

Referenced by OOTimeProfileEntry(Private)::addSampleWithTotalTime:selfTime:, GLDumpCullingState(), GLDumpFogState(), GLDumpLightState(), GLDumpMaterialState(), GLDumpStateFlags(), LogOpenGLState(), OOCheckOpenGLErrors(), OOJSEndProfiling(), and VerifyOpenGLStateInternal().

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

◆ OOLogPopIndent()

void OOLogPopIndent ( void )

Definition at line 340 of file OOLogging.m.

341{
342 OOLogIndentStackElement *elem = NULL;
343 NSMutableDictionary *threadDict = nil;
344 NSValue *val = nil;
345
346 threadDict = [[NSThread currentThread] threadDictionary];
347 val = [threadDict objectForKey:kIndentStackKey];
348
349 elem = [val pointerValue];
350
351 if (elem != NULL)
352 {
353 [threadDict setObject:[NSNumber numberWithUnsignedInt:elem->indent] forKey:kIndentLevelKey];
354 [threadDict setObject:[NSValue valueWithPointer:elem->link] forKey:kIndentStackKey];
355 free(elem);
356 }
357 else
358 {
359 OOLogInternal(OOLOG_BAD_POP_INDENT, @"OOLogPopIndent(): state stack underflow.");
360 }
361}
#define OOLOG_BAD_POP_INDENT
Definition OOLogging.m:68

References nil, OOLOG_BAD_POP_INDENT, and OOLogInternal.

◆ OOLogPushIndent()

void OOLogPushIndent ( void )

Definition at line 316 of file OOLogging.m.

317{
318 OOLogIndentStackElement *elem = NULL;
319 NSMutableDictionary *threadDict = nil;
320 NSValue *val = nil;
321
322 elem = malloc(sizeof *elem);
323 if (elem != NULL)
324 {
325 threadDict = [[NSThread currentThread] threadDictionary];
326 val = [threadDict objectForKey:kIndentStackKey];
327
328 elem->indent = [[threadDict objectForKey:kIndentLevelKey] intValue];
329 elem->link = [val pointerValue];
330
331 /*
332 Clang static analyzer reports elem not released here. It is in fact
333 released in OOLogPopIndent().
334 */
335 [threadDict setObject:[NSValue valueWithPointer:elem] forKey:kIndentStackKey];
336 }
337}
OOLogIndentStackElement * link
Definition OOLogging.m:76

References OOLogIndentStackElement::indent, OOLogIndentStackElement::link, and nil.

◆ OOLogSetDisplayMessagesInClass()

void OOLogSetDisplayMessagesInClass ( NSString * inClass,
BOOL inFlag )

Definition at line 182 of file OOLogging.m.

183{
184 id value = nil;
185
186 if (!Inited()) return;
187
188 [sLock lock];
189 value = [sExplicitSettings objectForKey:inClass];
190 if (value == nil || value != CacheValue(inFlag))
191 {
192 OOLogInternal(OOLOG_SETTING_SET, @"Setting %@ to %s", inClass, inFlag ? "ON" : "OFF");
193
194 [sExplicitSettings setObject:CacheValue(inFlag) forKey:inClass];
195
196 // Clear cache and let it be rebuilt as needed.
198 }
199 else
200 {
201 OOLogInternal(OOLOG_SETTING_SET, @"Keeping %@ %s", inClass, inFlag ? "ON" : "OFF");
202 }
203 [sLock unlock];
204}
OOINLINE BOOL Inited(void)
Definition OOLogging.m:136

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

Referenced by ConsoleSetDisplayMessagesInClass().

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

◆ OOLogSetShowFileAndLine()

void OOLogSetShowFileAndLine ( BOOL flag)

Definition at line 531 of file OOLogging.m.

532{
533 flag = !!flag; // YES or NO, not 42.
534
535 if (flag != sShowFileAndLine)
536 {
537 sShowFileAndLine = flag;
538 [[NSUserDefaults standardUserDefaults] setBool:flag forKey:@"logging-show-file-and-line"];
539 }
540}

References sShowFileAndLine.

◆ OOLogSetShowFunction()

void OOLogSetShowFunction ( BOOL flag)

Definition at line 513 of file OOLogging.m.

514{
515 flag = !!flag; // YES or NO, not 42.
516
517 if (flag != sShowFunction)
518 {
519 sShowFunction = flag;
520 [[NSUserDefaults standardUserDefaults] setBool:flag forKey:@"logging-show-function"];
521 }
522}

References sShowFunction.

◆ OOLogSetShowMessageClass()

void OOLogSetShowMessageClass ( BOOL flag)

Definition at line 567 of file OOLogging.m.

568{
569 flag = !!flag; // YES or NO, not 42.
570
571 if (flag != sShowClass)
572 {
573 sShowClass = flag;
574 [[NSUserDefaults standardUserDefaults] setBool:flag forKey:@"logging-show-class"];
575 }
576}

References sShowClass.

◆ OOLogSetShowMessageClassTemporary()

void OOLogSetShowMessageClassTemporary ( BOOL flag)

Definition at line 579 of file OOLogging.m.

580{
581 sShowClass = !!flag; // YES or NO, not 42.
582}

References sShowClass.

◆ OOLogSetShowTime()

void OOLogSetShowTime ( BOOL flag)

Definition at line 549 of file OOLogging.m.

550{
551 flag = !!flag; // YES or NO, not 42.
552
553 if (flag != sShowTime)
554 {
555 sShowTime = flag;
556 [[NSUserDefaults standardUserDefaults] setBool:flag forKey:@"logging-show-time"];
557 }
558}

References sShowTime.

◆ OOLogShowFileAndLine()

BOOL OOLogShowFileAndLine ( void )

Definition at line 525 of file OOLogging.m.

526{
527 return sShowFileAndLine;
528}

References sShowFileAndLine.

◆ OOLogShowFunction()

BOOL OOLogShowFunction ( void )

Definition at line 507 of file OOLogging.m.

508{
509 return sShowFunction;
510}

References sShowFunction.

◆ OOLogShowMessageClass()

BOOL OOLogShowMessageClass ( void )

Definition at line 561 of file OOLogging.m.

562{
563 return sShowClass;
564}

References sShowClass.

◆ OOLogShowTime()

BOOL OOLogShowTime ( void )

Definition at line 543 of file OOLogging.m.

544{
545 return sShowTime;
546}

References sShowTime.

◆ OOLogWillDisplayMessagesInClass()

BOOL OOLogWillDisplayMessagesInClass ( NSString * inMessageClass)

Definition at line 144 of file OOLogging.m.

145{
146 id value = nil;
147
148 if (!Inited()) return NO;
149
151
152 [sLock lock];
153
154 // Look for cached value
155 value = [sDerivedSettingsCache objectForKey:inMessageClass];
156 if (EXPECT_NOT(value == nil))
157 {
158 @try
159 {
160 // No cached value.
161 value = ResolveDisplaySetting(inMessageClass);
162
163 if (value != nil)
164 {
165 if (EXPECT_NOT(sDerivedSettingsCache == nil)) sDerivedSettingsCache = [[NSMutableDictionary alloc] init];
166 [sDerivedSettingsCache setObject:value forKey:inMessageClass];
167 }
168 }
169 @catch (id exception)
170 {
171 [sLock unlock];
172 @throw exception;
173 }
174 }
175 [sLock unlock];
176
177 OOLogInternal(OOLOG_SETTING_RETRIEVE, @"%@ is %s", inMessageClass, (value == kTrueToken) ? "on" : "off");
178 return value == kTrueToken;
179}
#define OOLOG_SETTING_RETRIEVE
Definition OOLogging.m:64
static id ResolveDisplaySetting(NSString *inMessageClass)
Definition OOLogging.m:861

References EXPECT_NOT, Inited(), kTrueToken, nil, OOLOG_SETTING_RETRIEVE, OOLogInternal, ResolveDisplaySetting(), sDerivedSettingsCache, sOverrideInEffect, and sOverrideValue.

Referenced by ConsoleDisplayMessagesInClass(), GlobalLog(), LogOpenGLState(), OOCheckOpenGLErrors(), OOLogWithFunctionFileAndLineAndArguments(), OOLogWithPrefix(), OONSLogCStringFunction(), ReportJSError(), SyntaxIssue(), and VerifyOpenGLStateInternal().

+ Here is the call graph for this function:
+ 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 397 of file OOLogging.m.

398{
399 va_list args;
400
401 va_start(args, inFormat);
402 OOLogWithFunctionFileAndLineAndArguments(inMessageClass, inFunction, inFile, inLine, inFormat, args);
403 va_end(args);
404}
void OOLogWithFunctionFileAndLineAndArguments(NSString *inMessageClass, const char *inFunction, const char *inFile, unsigned long inLine, NSString *inFormat, va_list inArguments)
Definition OOLogging.m:407

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 407 of file OOLogging.m.

408{
409 NSAutoreleasePool *pool = nil;
410 NSString *formattedMessage = nil;
411 unsigned indentLevel;
412
413 if (inFormat == nil) return;
414
415#if !OOLOG_SHORT_CIRCUIT
416 if (!OOLogWillDisplayMessagesInClass(inMessageClass)) return;
417#endif
418
419 pool = [[NSAutoreleasePool alloc] init];
420 @try
421 {
422 // Do argument substitution
423 formattedMessage = [[[NSString alloc] initWithFormat:inFormat arguments:inArguments] autorelease];
424
425 // Apply various prefix options
426 #ifndef OOLOG_NO_FILE_NAME
427 if (sShowFileAndLine && inFile != NULL)
428 {
429 if (sShowFunction)
430 {
431 formattedMessage = [NSString stringWithFormat:@"%s (%@:%lu): %@", inFunction, OOLogAbbreviatedFileName(inFile), inLine, formattedMessage];
432 }
433 else
434 {
435 formattedMessage = [NSString stringWithFormat:@"%@:%lu: %@", OOLogAbbreviatedFileName(inFile), inLine, formattedMessage];
436 }
437 }
438 else
439 #endif
440 {
441 if (sShowFunction)
442 {
443 formattedMessage = [NSString stringWithFormat:@"%s: %@", inFunction, formattedMessage];
444 }
445 }
446
447 if (sShowClass)
448 {
450 {
451 formattedMessage = [NSString stringWithFormat:@"[%@] %@", inMessageClass, formattedMessage];
452 }
453 else
454 {
455 formattedMessage = [NSString stringWithFormat:@"[%@]: %@", inMessageClass, formattedMessage];
456 }
457 }
458
459 if (sShowTime)
460 {
461 formattedMessage = [NSString stringWithFormat:@"%@ %@", [[NSDate date] descriptionWithCalendarFormat:@"%H:%M:%S.%F" timeZone:nil locale:nil], formattedMessage];
462 }
463
464 // Apply indentation
465 indentLevel = GetIndentLevel();
466 if (indentLevel != 0)
467 {
468 #define INDENT_FACTOR 2 /* Spaces per indent level */
469 #define MAX_INDENT 64 /* Maximum number of indentation _spaces_ */
470
471 unsigned indent;
472 // String of 64 spaces (null-terminated)
473 const char spaces[MAX_INDENT + 1] =
474 " ";
475 const char *indentString;
476
477 indent = INDENT_FACTOR * indentLevel;
478 if (MAX_INDENT < indent) indent = MAX_INDENT;
479 indentString = &spaces[MAX_INDENT - indent];
480
481 formattedMessage = [NSString stringWithFormat:@"%s%@", indentString, formattedMessage];
482 }
483
484 OOLogOutputHandlerPrint(formattedMessage);
485 }
486 @catch (NSException *exception)
487 {
488 OOLogInternal(OOLOG_EXCEPTION_IN_LOG, @"***** Exception thrown during logging: %@ : %@", [exception name], [exception reason]);
489 }
490
491 [pool release];
492}
BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
Definition OOLogging.m:144
#define OOLOG_EXCEPTION_IN_LOG
Definition OOLogging.m:69
#define MAX_INDENT
#define INDENT_FACTOR

References GetIndentLevel(), OOLogIndentStackElement::indent, 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 387 of file OOLogging.m.

388{
389 if (!OOLogWillDisplayMessagesInClass(inMessageClass)) return;
390 va_list args;
391 va_start(args, inFormat);
392 OOLogWithFunctionFileAndLineAndArguments(inMessageClass, inFunction, inFile, inLine, [inPrefix stringByAppendingString:inFormat], args);
393 va_end(args);
394}

References OOLogWillDisplayMessagesInClass(), and OOLogWithFunctionFileAndLineAndArguments().

+ Here is the call graph for this function:

◆ ResolveDisplaySetting()

static id ResolveDisplaySetting ( NSString * inMessageClass)
static

Definition at line 861 of file OOLogging.m.

862{
863 id value = nil;
864 NSMutableSet *seenMetaClasses = nil;
865
866 if (inMessageClass == nil) return CacheValue(sDefaultDisplay);
867
868 value = [sExplicitSettings objectForKey:inMessageClass];
869
870 // Simple case: explicit setting for this value
871 if (value == kTrueToken || value == kFalseToken) return value;
872
873 // Simplish case: use inherited value
874 if (value == nil || value == kInheritToken) return ResolveDisplaySetting(OOLogGetParentMessageClass(inMessageClass));
875
876 // Less simple case: should be a metaclass.
877 seenMetaClasses = [NSMutableSet set];
878 return ResolveMetaClassReference(value, seenMetaClasses);
879}
NSString * OOLogGetParentMessageClass(NSString *inClass)
Definition OOLogging.m:207
static NSString *const kInheritToken
Definition OOLogging.m:102
static id ResolveMetaClassReference(NSString *inMetaClass, NSMutableSet *ioSeenMetaClasses)
Definition OOLogging.m:885

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()

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

Definition at line 885 of file OOLogging.m.

886{
887 id value = nil;
888
889 // All values should have been checked at load time, but what the hey.
890 if (![inMetaClass isKindOfClass:[NSString class]] || ![inMetaClass hasPrefix:@"$"])
891 {
892 OOLogInternal(OOLOG_BAD_SETTING, @"Bad setting value \"%@\" (expected yes, no, inherit or $metaclass). Falling back to _default.", inMetaClass);
894 }
895
896 [ioSeenMetaClasses addObject:inMetaClass];
897
898 value = [sExplicitSettings objectForKey:inMetaClass];
899
900 if (value == kTrueToken || value == kFalseToken) return value;
901 if (value == nil)
902 {
903 OOLogInternal(OOLOG_UNDEFINED_METACLASS, @"Reference to undefined metaclass %@, falling back to _default.", inMetaClass);
905 }
906
907 // If we get here, it should be a metaclass reference.
908 return ResolveMetaClassReference(value, ioSeenMetaClasses);
909}
#define OOLOG_UNDEFINED_METACLASS
Definition OOLogging.m:65

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 309 of file OOLogging.m.

310{
311 NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary];
312 [threadDict setObject:[NSNumber numberWithUnsignedInt:value] forKey:kIndentLevelKey];
313}

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 52 of file OOLogging.m.

◆ kIndentStackKey

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

Definition at line 53 of file OOLogging.m.

◆ kInheritToken

NSString* const kInheritToken = @"inherit"
static

Definition at line 102 of file OOLogging.m.

Referenced by ResolveDisplaySetting().

◆ kOOLogAllocationFailure

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

Definition at line 649 of file OOLogging.m.

Referenced by OOMeshToOctreeConverter::addTriangle:.

◆ kOOLogDeprecatedMethod

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

Definition at line 648 of file OOLogging.m.

◆ kOOLogException

NSString* const kOOLogException = @"exception"

Definition at line 651 of file OOLogging.m.

Referenced by AI::clearAllData, main(), MissionRunCallback(), and OOJSDumpStack().

◆ kOOLogFileNotFound

NSString* const kOOLogFileNotFound = @"files.notFound"

Definition at line 652 of file OOLogging.m.

◆ kOOLogFileNotLoaded

NSString* const kOOLogFileNotLoaded = @"files.notLoaded"

Definition at line 653 of file OOLogging.m.

◆ kOOLogInconsistentState

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

Definition at line 650 of file OOLogging.m.

◆ kOOLogOpenGLError

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

Definition at line 654 of file OOLogging.m.

Referenced by OOCheckOpenGLErrors().

◆ kOOLogParameterError

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

◆ kOOLogSubclassResponsibility

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

Definition at line 646 of file OOLogging.m.

Referenced by OOLogGenericSubclassResponsibilityForFunction().

◆ kOOLogUnconvertedNSLog

NSString* const kOOLogUnconvertedNSLog = @"unclassified"

Definition at line 655 of file OOLogging.m.

◆ kTrueToken

◆ sDefaultDisplay

BOOL sDefaultDisplay = YES
static

◆ sDerivedSettingsCache

NSMutableDictionary* sDerivedSettingsCache = nil
static

◆ sExplicitSettings

NSMutableDictionary* sExplicitSettings = nil
static

Definition at line 84 of file OOLogging.m.

Referenced by LoadExplicitSettings().

◆ sFileNamesCache

NSMapTable* sFileNamesCache = NULL
static

Definition at line 121 of file OOLogging.m.

Referenced by OOLogAbbreviatedFileName(), and OOLoggingInit().

◆ sInited

BOOL sInited = NO
static

Definition at line 82 of file OOLogging.m.

Referenced by Inited(), OOLoggingInit(), and OOLoggingTerminate().

◆ sLock

NSLock* sLock = nil
static

Definition at line 83 of file OOLogging.m.

Referenced by OOLoggingInit().

◆ sOverrideInEffect

BOOL sOverrideInEffect = NO
static

Definition at line 96 of file OOLogging.m.

Referenced by LoadExplicitSettings(), and OOLogWillDisplayMessagesInClass().

◆ sOverrideValue

BOOL sOverrideValue = NO
static

Definition at line 97 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