So I gave up on this back then, and have tried to revisit this again today.
No matter what I do, I can’t get this to work.
Here is what I am trying to do, when a module is loaded I have an interceptor with postModuleLoad, which then does this.
if(interceptData.modulename == ‘myModule’) {
log.info(‘Module Name #interceptData.modulename#’);
var logboxConfig = logbox.getConfig();
logboxConfig.appender(name=‘myModuleTracer’,
class=“coldbox.system.logging.appenders.RollingFileAppender”,
properties = {filePath=’/logs’, fileName=‘myModule’, autoExpand=true, fileMaxSize=1000, fileMaxArchives=9}
);
var componentNames = directoryList( moduleSetting.path, true, “query”, “*.cfc”, “name asc” );
for(var file in componentNames) {
var cleanPath = replacenocase(file.directory, expandPath(modulesPath), “”, “all”);
cleanPath = “modules.” & removeChars(replacenocase(cleanPath, “”, “.”, “all”), 1, 1);
var catergoryName = cleanPath & “.” & replaceNoCase(file.name, “.cfc”, “”);
if(!logboxConfig.categoryExists(catergoryName)) {
logboxConfig.category(name = catergoryName, appenders = “myModuleTracer”);
}
}
}
Which works, if I dump the getAllAppenders or getAllCategories, everything looks fine. However, when I do something like this in a service or handler.
property name=“log” inject=“logbox:logger:{this}”;
I get an error…
Error Type: Builder.BuildCFCDependencyException : [N/A]
Error Messages: Error building: modules.myModule.handlers.security -> Element myModuleTracer is undefined in a CFML structure referenced as part of an expression. with constructor arguments: {controller={[(Component=coldbox.system.web.Controller)]}}
Now I have tracked this back to the following lines in LogBox.cfc.
//Do we have a category definition, so we can build it?
if( instance.config.categoryExists(arguments.category) ){
categoryConfig = instance.config.getCategory(arguments.category);
// Setup creation arguments
args.category = categoryConfig.name;
args.levelMin = categoryConfig.levelMin;
args.levelMax = categoryConfig.levelMax;
writeDump(categoryConfig);
args.appenders = getAppendersMap(categoryConfig.appenders);
}
else{
// Setup new category name
args.category = arguments.category;
// Do Category Inheritance? or else just return the root logger.
root = locateCategoryParentLogger(arguments.category);
// Setup the category levels according to parent found.
args.levelMin = root.getLevelMin();
args.levelMax = root.getLevelMax();
}
The actual line it is falling over on is the getAppendersMap() above, and to test this I then went into that method and placed a try catch around this.
for(x=1; x lte listlen(arguments.appenders); x=x+1){
thisAppender = listGetAt(arguments.appenders,x);
appendersMap[thisAppender] = instance.appenderRegistry[thisAppender];
}
And in the catch dumped out the appendersRegistry and appenders, it is interesting to note that the categories are all there, but the appender no longer exists.
Now, if I go back to the interceptor and comment out the line where it adds the category and rerun the application it will not error. In fact if I go into a handler and dump all the appenders and categories everything looks fine. So it appears that adding appenders dynamically, is missing a step as the appender is actually missing when it is needed.
Question now is, how the hell do I add appenders and categories as the documentation on this is really self explanatory. But it doesn’t work.