Import OOLogging from OOCocoa.h. Rearranged logcontrol.plist. Changed to camelCase for both message classes and metaclasses. Added ability to override an explicit logcontrol.plist setting with 'inherit'.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@812 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2007-03-04 11:22:06 +00:00
parent 1c6dfae3e2
commit ba718f3b70
11 changed files with 127 additions and 123 deletions

View File

@ -21,86 +21,91 @@
*/
_default = yes; // Fallback value for otherwise undefined classes. Must be yes or no.
// _override = yes; // Use to force display of all messages (or suppress all messages). Must be yes or no.
_default = yes; // Fallback value for otherwise undefined classes. Must be yes or no.
// _override = yes; // Use to force display of all messages (or suppress all messages). Must be yes or no.
$script_error = yes;
$scriptError = yes;
$error = yes;
$trouble_shooting_dump = yes;
$entity_state = yes;
$troubleShootingDump = yes;
$entityState = yes;
// These are common types of programming problems
general = inherit;
general.subclassresponsibility = $error;
general.parametererror = $error;
general.subclassResponsibility = $error;
general.parameterError = $error;
exception = yes;
files = inherit;
files.notfound = $error; // Failure to load a file.
files.notloaded = $error; // A file should have been loaded at some earlier point, but wasnt.
files.notFound = $error; // Failure to load a file.
files.notLoaded = $error; // A file should have been loaded at some earlier point, but wasnt.
scripting = inherit;
scripting.debug = inherit;
scripting.debug.message = inherit;
scripting.debug.onoff = inherit;
scripting.scriptaction = $entity_state;
scripting.scriptaction.scriptaction = inherit;
scripting.scriptaction.noaction = inherit;
scripting.scriptaction.expanded = inherit;
scripting.scriptaction.badselector = $script_error;
scripting.spawn = inherit;
scripting.spawn.spawned = inherit;
scripting.spawn.failed = $script_error;
// Module-specific stuff follows
ai = $entityState;
ai.message = inherit;
ai.message.receive = inherit;
ai.takeAction = inherit;
ai.takeAction.takeAction = $entityState;
ai.takeAction.noAction = $entityState;
ai.takeAction.orphaned = $error;
ai.takeAction.debugMessage = inherit;
ai.takeAction.badSelector = $scriptError;
dataCache = inherit;
dataCache.found = inherit;
dataCache.notFound = inherit;
dataCache.rebuild = inherit;
$linkedListError = $error;
entity = inherit;
entity.linkedList = inherit; // Management/verification of the lists used to track the relative position of entities.
entity.linkedList.add = inherit;
entity.linkedList.add.error = $linkedListError;
entity.linkedList.remove = inherit;
entity.linkedList.remove.error = $linkedListError;
entity.linkedList.verify.error = $linkedListError;
entity.linkedList.update.error = $linkedListError;
entity.behaviour = inherited;
entity.behaviour.changed = $entityState;
input = inherit;
input.keyMapping = inherit;
input.keyMapping.codeOutOfRange = inherit;
rendering = inherit;
rendering.opengl = inherit;
rendering.opengl.error = $error; // Test for and display OpenGL errors
rendering.opengl.version = $trouble_shooting_dump; // Display renderer version information at startup
rendering.opengl.extensions = $trouble_shooting_dump; // List OpenGL extensions at startup
rendering.opengl.version = $troubleShootingDump; // Display renderer version information at startup
rendering.opengl.extensions = $troubleShootingDump; // List OpenGL extensions at startup
rendering.opengl.shaders = inherit; // Shader-related messages
rendering.opengl.shaders.support = $trouble_shooting_dump; // Messages about factors influencing availability of OpenGL shaders
rendering.opengl.statedump = $trouble_shooting_dump; // Dump of OpenGL state (debug tool, currently unused)
rendering.opengl.shaders.support = $troubleShootingDump; // Messages about factors influencing availability of OpenGL shaders
rendering.opengl.stateDump = $troubleShootingDump; // Dump of OpenGL state (debug tool, currently unused)
scripting = $entityState;
scripting.debug = inherit;
scripting.debug.message = yes; // debugMessage: script action
scripting.debug.onOff = inherit; // debugOn/debugOff script actions
scripting.scriptAction = $entityState;
scripting.scriptAction.scriptAction = inherit;
scripting.scriptAction.noAction = inherit;
scripting.scriptAction.expanded = inherit;
scripting.scriptAction.badSelector = $scriptError;
scripting.spawn = inherit;
scripting.spawn.spawned = inherit;
scripting.spawn.failed = $scriptError;
searchpaths = inherit;
searchpaths.dumpall = $trouble_shooting_dump;
searchpaths.dumpAll = $troubleShootingDump;
strings = inherit;
strings.conversion = $script_error; // Conversion of text to values (vectors, quaternions etc)
strings.conversion = $scriptError; // Conversion of text to values (vectors, quaternions etc)
strings.conversion.vector = inherit;
strings.conversion.quaternion = inherit;
strings.conversion.vectorandquaternion = inherit;
strings.conversion.randomseed = inherit;
$linked_list_error = $error;
entity = inherit;
entity.linkedlist = inherit; // Management/verification of the lists used to track the relative position of entities.
entity.linkedlist.add = inherit;
entity.linkedlist.add.error = $linked_list_error;
entity.linkedlist.remove = inherit;
entity.linkedlist.remove.error = $linked_list_error;
entity.linkedlist.verify.error = $linked_list_error;
entity.linkedlist.update.error = $linked_list_error;
entity.behaviour = inherited;
entity.behaviour.changed = $entity_state;
ai = inherit;
ai.message = inherit;
ai.message.receive = inherit;
ai.takeaction = inherit;
ai.takeaction.takeaction = $entity_state;
ai.takeaction.noaction = $entity_state;
ai.takeaction.orphaned = $error;
ai.takeaction.debugmessage = inherit;
ai.takeaction.badselector = $script_error;
datacache = inherit;
datacache.found = inherit;
datacache.notfound = inherit;
datacache.rebuild = inherit;
strings.conversion.vectorAndQuaternion = inherit;
strings.conversion.randomSeed = inherit;
universe = inherit;
universe.populate = $trouble_shooting_dump; // “Populating a system with…” message when generating a star system
universe.populate = $troubleShootingDump; // “Populating a system with…” message when generating a star system
// Mac-specific
growl = inherit;

View File

@ -28,7 +28,6 @@ MA 02110-1301, USA.
#import "GuiDisplayGen.h"
#import "Universe.h"
#import "PlayerEntity.h"
#import "OOLogging.h"
static NSString * const kOOLogGrooliteError = @"growl.error";
static NSString * const kOOLogGrooliteDebug = @"growl.debug";

View File

@ -29,7 +29,11 @@ MA 02110-1301, USA.
#import "TextureStore.h"
#import "Entity.h"
#import "PlanetEntity.h"
#import "ResourceManager.h"
#import "ResourceManager.h"'
static NSString * kOOLogKeyCodeOutOfRange = @"input.keyMapping.codeOutOfRange";
@interface MyOpenGLView(Internal)
@ -362,7 +366,7 @@ MA 02110-1301, USA.
else
{
if (key > [self numKeys])
NSLog(@"***** translated key: %d out of range\n", key);
OOLog(kOOLogKeyCodeOutOfRange, @"Translated key: %d out of range\n", key);
}
}
@ -429,7 +433,7 @@ MA 02110-1301, USA.
else
{
if (key > [self numKeys])
NSLog(@"***** translated key: %d out of range\n", key);
OOLog(kOOLogKeyCodeOutOfRange, @"Translated key: %d out of range\n", key);
}
}

View File

@ -26,15 +26,14 @@ MA 02110-1301, USA.
#import "entities.h"
#import "ResourceManager.h"
#import "OOInstinct.h"
#import "OOLogging.h"
static NSString * const kOOLogAIReceiveMessage = @"ai.message.receive";
static NSString * const kOOLogAITakeAction = @"ai.takeaction.takeaction";
static NSString * const kOOLogAINoAction = @"ai.takeaction.noaction";
static NSString * const kOOLogAITakeActionOrphaned = @"ai.takeaction.orphaned";
static NSString * const kOOLogAIDebugMessage = @"ai.takeaction.debugmessage";
static NSString * const kOOLogAIBadSelector = @"ai.takeaction.badselector";
static NSString * const kOOLogAITakeAction = @"ai.takeAction.takeAction";
static NSString * const kOOLogAINoAction = @"ai.takeAction.noAction";
static NSString * const kOOLogAITakeActionOrphaned = @"ai.takeAction.orphaned";
static NSString * const kOOLogAIDebugMessage = @"ai.takeAction.debugNessage";
static NSString * const kOOLogAIBadSelector = @"ai.takeAction.badSelector";
@implementation AI

View File

@ -30,23 +30,22 @@ MA 02110-1301, USA.
#import "GameController.h"
#import "TextureStore.h"
#import "ResourceManager.h"
#import "OOLogging.h"
#import "CollisionRegion.h" // gets rid of a compilation warning
#import "NSScannerOOExtensions.h"
static NSString * const kOOLogEntityAddToList = @"entity.linkedlist.add";
static NSString * const kOOLogEntityAddToListError = @"entity.linkedlist.add.error";
static NSString * const kOOLogEntityRemoveFromList = @"entity.linkedlist.remove";
static NSString * const kOOLogEntityRemoveFromListError = @"entity.linkedlist.remove.error";
static NSString * const kOOLogEntityVerificationError = @"entity.linkedlist.verify.error";
static NSString * const kOOLogEntityUpdateError = @"entity.linkedlist.update.error";
static NSString * const kOOLogEntityAddToList = @"entity.linkedList.add";
static NSString * const kOOLogEntityAddToListError = @"entity.linkedList.add.error";
static NSString * const kOOLogEntityRemoveFromList = @"entity.linkedList.remove";
static NSString * const kOOLogEntityRemoveFromListError = @"entity.linkedList.remove.error";
static NSString * const kOOLogEntityVerificationError = @"entity.linkedList.verify.error";
static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.error";
static NSString * const kOOLogStringVectorConversion = @"strings.conversion.vector";
static NSString * const kOOLogStringQuaternionConversion = @"strings.conversion.quaternion";
static NSString * const kOOLogStringVecAndQuatConversion = @"strings.conversion.vectorandquaternion";
static NSString * const kOOLogStringRandomSeedConversion = @"strings.conversion.randomseed";
static NSString * const kOOLogStringVecAndQuatConversion = @"strings.conversion.vectorAndQuaternion";
static NSString * const kOOLogStringRandomSeedConversion = @"strings.conversion.randomSeed";
// global flag for VAR

View File

@ -160,3 +160,5 @@ enum {
#import <AppKit/AppKit.h>
#endif
#import "OOLogging.h"

View File

@ -51,7 +51,6 @@ static NSLock *sLock = nil;
static NSMutableDictionary *sExplicitSettings = nil;
static NSMutableDictionary *sDerivedSettingsCache = nil;
static NSMutableDictionary *sFileNamesCache = nil;
static NSNumber *sCacheTrue = nil, *sCacheFalse = nil; // These are the only values that may appear in sDerivedSettingsCache.
static unsigned sIndentLevel = 0;
static BOOL sShowFunction = NO;
static BOOL sShowFileAndLine = NO;
@ -61,6 +60,11 @@ static BOOL sShowApplication = SHOW_APPLICATION;
static BOOL sOverrideInEffect = NO;
static BOOL sOverrideValue = NO;
// These specific values are used for true, false and inherit in the cache and explicitSettings dictionaries so we can use pointer comparison.
static NSNumber * const kTrueToken = @"on";
static NSNumber * const kFalseToken = @"off";
static NSString * const kInheritToken = @"inherit";
// To avoid recursion/self-dependencies, OOLog gets its own logging function.
#define OOLogInternal(cond, format, ...) do { if ((cond)) { OOLogInternal_(OOLOG_FUNCTION_NAME, format, ## __VA_ARGS__); }} while (0)
@ -68,7 +72,7 @@ static void OOLogInternal_(const char *inFunction, NSString *inFormat, ...);
static void LoadExplicitSettings(void);
static void LoadExplicitSettingsFromDictionary(NSDictionary *inDict);
static void LoadExplicitSettingsFromDictionary(NSDictionary *inDict, BOOL inExplicitInherit);
static NSString *AbbreviatedFileName(const char *inName);
static NSNumber *ResolveDisplaySetting(NSString *inMessageClass);
static NSNumber *ResolveMetaClassReference(NSString *inMetaClass, NSMutableSet *ioSeenMetaClasses);
@ -87,7 +91,7 @@ static inline void PrimitiveLog(NSString *inString)
static inline NSNumber *CacheValue(BOOL inValue)
{
return inValue ? sCacheTrue : sCacheFalse;
return inValue ? kTrueToken : kFalseToken;
}
@ -121,8 +125,8 @@ BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
}
[sLock unlock];
OOLogInternal(OOLOG_SETTING_RETRIEVE, @"%@ is %s", inMessageClass, (value == sCacheTrue) ? "on" : "off");
return value == sCacheTrue;
OOLogInternal(OOLOG_SETTING_RETRIEVE, @"%@ is %s", inMessageClass, (value == kTrueToken) ? "on" : "off");
return value == kTrueToken;
}
@ -298,17 +302,17 @@ void OOLoggingInit(void)
}
NSString * const kOOLogSubclassResponsibility = @"general.subclassresponsibility";
NSString * const kOOLogParameterError = @"general.parametererror";
NSString * const kOOLogSubclassResponsibility = @"general.subclassResponsibility";
NSString * const kOOLogParameterError = @"general.parameterError";
NSString * const kOOLogException = @"exception";
NSString * const kOOLogFileNotFound = @"files.notfound";
NSString * const kOOLogFileNotLoaded = @"files.notloaded";
NSString * const kOOLogFileNotFound = @"files.notFound";
NSString * const kOOLogFileNotLoaded = @"files.notLoaded";
NSString * const kOOLogOpenGLError = @"rendering.opengl.error";
NSString * const kOOLogOpenGLVersion = @"rendering.opengl.version";
NSString * const kOOLogOpenGLShaderSupport = @"rendering.opengl.shaders.support";
NSString * const kOOLogOpenGLExtensions = @"rendering.opengl.extensions";
NSString * const kOOLogOpenGLExtensionsVAR = @"rendering.opengl.extensions.var";
NSString * const kOOLogOpenGLStateDump = @"rendering.opengl.statedump";
NSString * const kOOLogOpenGLStateDump = @"rendering.opengl.stateDump";
static void OOLogInternal_(const char *inFunction, NSString *inFormat, ...)
@ -344,28 +348,25 @@ static void LoadExplicitSettings(void)
sExplicitSettings = [[NSMutableDictionary alloc] init];
sCacheTrue = [[NSNumber numberWithBool:YES] retain];
sCacheFalse = [[NSNumber numberWithBool:NO] retain];
// Load defaults from logcontrol.plist
configPath = [[NSBundle mainBundle] pathForResource:@"logcontrol" ofType:@"plist"];
dict = [NSDictionary dictionaryWithContentsOfFile:configPath];
LoadExplicitSettingsFromDictionary(dict);
LoadExplicitSettingsFromDictionary(dict, NO);
// Get overrides from preferences
prefs = [NSUserDefaults standardUserDefaults];
dict = [prefs objectForKey:@"logging-enable"];
if ([dict isKindOfClass:[NSDictionary class]])
{
LoadExplicitSettingsFromDictionary(dict);
LoadExplicitSettingsFromDictionary(dict, YES);
}
// Get _default and _override value
value = [sExplicitSettings objectForKey:@"_default"];
if (value != nil && [value respondsToSelector:@selector(boolValue)])
{
if (value == sCacheTrue) sDefaultDisplay = YES;
else if (value == sCacheFalse) sDefaultDisplay = NO;
if (value == kTrueToken) sDefaultDisplay = YES;
else if (value == kFalseToken) sDefaultDisplay = NO;
else OOLogInternal(OOLOG_BAD_DEFAULT_SETTING, @"_default may not be set to a metaclass, ignoring.");
[sExplicitSettings removeObjectForKey:@"_default"];
@ -373,12 +374,12 @@ static void LoadExplicitSettings(void)
value = [sExplicitSettings objectForKey:@"_override"];
if (value != nil && [value respondsToSelector:@selector(boolValue)])
{
if (value == sCacheTrue)
if (value == kTrueToken)
{
sOverrideInEffect = YES;
sOverrideValue = YES;
}
else if (value == sCacheFalse)
else if (value == kFalseToken)
{
sOverrideInEffect = YES;
sOverrideValue = NO;
@ -414,7 +415,7 @@ static void LoadExplicitSettings(void)
}
static void LoadExplicitSettingsFromDictionary(NSDictionary *inDict)
static void LoadExplicitSettingsFromDictionary(NSDictionary *inDict, BOOL inExplicitInherit)
{
NSEnumerator *keyEnum = nil;
id key = nil;
@ -425,10 +426,10 @@ static void LoadExplicitSettingsFromDictionary(NSDictionary *inDict)
value = [inDict objectForKey:key];
/* Supported values:
"yes", "true" or "on" -> sCacheTrue
"no", "false" or "off" -> sCacheFalse
"yes", "true" or "on" -> kTrueToken
"no", "false" or "off" -> kFalseToken
"inherit" or "inherited" -> nil
NSNumber -> sCacheTrue or sCacheFalse
NSNumber -> kTrueToken or kFalseToken
"$metaclass" -> "$metaclass"
*/
if ([value isKindOfClass:[NSString class]])
@ -437,18 +438,18 @@ static void LoadExplicitSettingsFromDictionary(NSDictionary *inDict)
NSOrderedSame == [value caseInsensitiveCompare:@"true"] ||
NSOrderedSame == [value caseInsensitiveCompare:@"on"])
{
value = sCacheTrue;
value = kTrueToken;
}
else if (NSOrderedSame == [value caseInsensitiveCompare:@"no"] ||
NSOrderedSame == [value caseInsensitiveCompare:@"false"] ||
NSOrderedSame == [value caseInsensitiveCompare:@"off"])
{
value = sCacheFalse;
value = kFalseToken;
}
else if (NSOrderedSame == [value caseInsensitiveCompare:@"inherit"] ||
NSOrderedSame == [value caseInsensitiveCompare:@"inherited"])
{
value = nil;
value = inExplicitInherit ? kInheritToken : nil;
}
else if (![value hasPrefix:@"$"])
{
@ -504,10 +505,10 @@ static NSNumber *ResolveDisplaySetting(NSString *inMessageClass)
value = [sExplicitSettings objectForKey:inMessageClass];
// Simple case: explicit setting for this value
if (value == sCacheTrue || value == sCacheFalse) return value;
if (value == kTrueToken || value == kFalseToken) return value;
// Simplish case: nil == use inherited value
if (value == nil) return ResolveDisplaySetting(OOLogGetParentMessageClass(inMessageClass));
// Simplish case: use inherited value
if (value == nil || value == kInheritToken) return ResolveDisplaySetting(OOLogGetParentMessageClass(inMessageClass));
// Less simple case: should be a metaclass.
seenMetaClasses = [NSMutableSet set];
@ -530,7 +531,7 @@ static NSNumber *ResolveMetaClassReference(NSString *inMetaClass, NSMutableSet *
value = [sExplicitSettings objectForKey:inMetaClass];
if (value == sCacheTrue || value == sCacheFalse) return value;
if (value == kTrueToken || value == kFalseToken) return value;
if (value == nil)
{
OOLogInternal(OOLOG_UNDEFINED_METACLASS, @"Reference to undefined metaclass %@, falling back to _default.", inMetaClass);

View File

@ -30,18 +30,17 @@ MA 02110-1301, USA.
#import "AI.h"
#import "OOSound.h"
#import "OOColor.h"
#import "OOLogging.h"
#ifdef GNUSTEP
#import "Comparison.h"
#endif
static NSString * const kOOLogScriptDebugMessage = @"scripting.debug.message";
static NSString * const kOOLogScriptDebugOnOff = @"scripting.debug.onoff";
static NSString * const kOOLogScriptAction = @"scripting.scriptaction.scriptaction";
static NSString * const kOOLogScriptNoAction = @"scripting.scriptaction.noaction";
static NSString * const kOOLogScriptActionExpanded = @"scripting.scriptaction.expanded";
static NSString * const kOOLogScriptActionBadSelector = @"scripting.scriptaction.badselector";
static NSString * const kOOLogScriptDebugOnOff = @"scripting.debug.onOff";
static NSString * const kOOLogScriptAction = @"scripting.scriptAction.scriptAction";
static NSString * const kOOLogScriptNoAction = @"scripting.scriptAction.noAction";
static NSString * const kOOLogScriptActionExpanded = @"scripting.scriptAction.expanded";
static NSString * const kOOLogScriptActionBadSelector = @"scripting.scriptAction.badSelector";
NSString * const kOOLogScriptSpawnOK = @"scripting.spawn.spawned";
NSString * const kOOLogScriptSpawnFailed = @"scripting.spawn.failed";

View File

@ -26,10 +26,9 @@ MA 02110-1301, USA.
#import "NSScannerOOExtensions.h"
#import "NSMutableDictionaryOOExtensions.h"
#import "OOSound.h"
#import "OOLogging.h"
static NSString * const kOOLogDumpSearchPaths = @"searchpaths.dumpall";
static NSString * const kOOLogDumpSearchPaths = @"searchpaths.dumpAll";
extern NSDictionary* parseScripts(NSString* script);

View File

@ -39,12 +39,10 @@ MA 02110-1301, USA.
#import "NSScannerOOExtensions.h"
#import "OOColor.h"
#import "OOLogging.h"
extern NSString * const kOOLogScriptSpawnOK;
extern NSString * const kOOLogScriptSpawnFailed;
static NSString * const kOOLogEntityBehaviourChanged = @"entity.behaviour.changed";
static NSString * const kOOLogEntityBehaviourChanged = @"entity.behaviour.changed";
@implementation ShipEntity
@ -3300,7 +3298,7 @@ void testForShaders()
if ([vscan scanUpToCharactersFromSet:[NSCharacterSet characterSetWithCharactersInString:@". "] intoString:&temp])
minor = [temp intValue];
OOLog(kOOLogOpenGLVersion, @"\n\nOPENGL VERSION %d.%d ('%@')", major, minor, version_info);
OOLog(kOOLogOpenGLVersion, @"OpenGL renderer version: %d.%d ('%@')", major, minor, version_info);
if ((major < 2)&&(minor < 5))
{
@ -3312,7 +3310,7 @@ void testForShaders()
// check for the necessary extensions
NSString* extension_info = [NSString stringWithCString: (const char *)glGetString(GL_EXTENSIONS)];
OOLog(kOOLogOpenGLExtensions, @"\n\nOPENGL EXTENSIONS:\n%@", extension_info);
OOLog(kOOLogOpenGLExtensions, @"OPENGL EXTENSIONS:\n%@", extension_info);
shaders_supported &= ([extension_info rangeOfString:@"GL_ARB_multitexture"].location != NSNotFound);
if (!shaders_supported)

View File

@ -34,7 +34,6 @@ MA 02110-1301, USA.
#import "HeadUpDisplay.h"
#import "OOSound.h"
#import "OOColor.h"
#import "OOLogging.h"
#import "Octree.h"
#import "CollisionRegion.h"
@ -45,9 +44,9 @@ MA 02110-1301, USA.
#define MAX_NUMBER_OF_SOLAR_SYSTEM_ENTITIES 20
static NSString * const kOOLogDataCacheFound = @"datacache.found";
static NSString * const kOOLogDataCacheNotFound = @"datacache.notfound";
static NSString * const kOOLogDataCacheRebuild = @"datacache.rebuild";
static NSString * const kOOLogDataCacheFound = @"dataCache.found";
static NSString * const kOOLogDataCacheNotFound = @"dataCache.notFound";
static NSString * const kOOLogDataCacheRebuild = @"dataCache.rebuild";
static NSString * const kOOLogUniversePopulate = @"universe.populate";