[coldbox-5.3.0] Logbox categories and my modules

Always kinda fight with logbox but by god this time I’m going to win.

I want to have my named modules log to specific appenders so in my coldbox config, logbox defines testLog and securityLog properly (they get created on init) and the I define the following categories…

categories = { “coldbox.system” = { levelMin=“FATAL”, levelMax=“INFO”, appenders=“testLog” },
“modules.Security” = { levelMin=“FATAL”, levelMax=“DEBUG”, appenders=“securityLog” } }

According to the current docs, handlers are auto injected with “log” so in my root handlers, for example in Main, I simply do

this.getlog().info(“I am in home now”)

…and that gets written to the testlog every time I hit that handler method. Woot !

Now, for my simple security model, in the property of a service (modules/Security/models/SecurityService), I include

property name=“log” inject=“logbox:logger:{this}”;

and in the various methods therein, I simply do the same thing…

this.getLog().info(“user has been logged out at their request”)

…but nothing gets written…not to testLog (which I would not expect) and not to the secuirtyLog, which I DID expect. I don’t get any errors, nothing abends, just nothing writes. Obviously my thinking or my implementation is wrong. Current docs don’t give as many implementation examples as they used to. What would be ideal is a simple application with custom modules that illustrates how this works…always happy to work from / learn from example code.

Someone please, point me to my error? The whole logbox configuration in coldbox.cfc is below.

//LogBox DSL
logBox = {
// Define Appenders
appenders = { coldboxTracer = { class=“coldbox.system.logging.appenders.ConsoleAppender” },
testLog = { class=“coldbox.system.logging.appenders.RollingFileAppender”,
properties={ filePath=expandPath( “/logs” ),
autoExpand=true,
fileMaxArchives=3,
fileMaxSize=2000,
async=false }},
securityLog = { class=“coldbox.system.logging.appenders.RollingFileAppender”,
properties={ filePath=expandPath( “/logs” ),
autoExpand=true,
fileMaxArchives=3,
fileMaxSize=2000,
async=false }}
},
// Root Logger
root = { levelmax=“INFO”, appenders=“testLog” },

// Categories

categories = { “coldbox.system” = { levelMin=“FATAL”, levelMax=“INFO”, appenders=“testLog” },
“modules.Security.models” = { levelMin=“FATAL”, levelMax=“DEBUG”, appenders=“securityLog” }
}
};

Thanks for any help anyone can provide.

Mike

You need to check and see what the category of your logger is. When you use the “this” trick, it’s the same as getMetadata( this ).name which in your case is likely security.models.SecurityService and NOT modules.security.models.SecurityService which likely explains why your category config isn’t getting used. You can easily tell the name of the logger by looking in one of the log files that are getting logged to. The logger category/name (same thing) is part of the log message.