Hi,
I want to log from different places in my application to different log files:
models.UserService to userLog
security module to securityLog
error handler to appLog
The logger is always injected using inject = “logbox:logger:{this}”.
The issue I have is that all my messages are always logged in the 3 log files instead of 1 specific log file.
Can anybody tell me what I am missing?
This is my config LogBox.cfc
`
component{
// Configure LogBox
function configure(){
//LogBox DSL
logBox = {
// Define Appenders
appenders = {
coldboxTracer = { class=“coldbox.system.logging.appenders.ConsoleAppender” },
coldboxLog = {
class=“coldbox.system.logging.appenders.FileAppender”,
properties = {
filepath = “/logs/”,
filename = “appLog”
}
},
userLog = {
class=“coldbox.system.logging.appenders.FileAppender”,
properties = {
filepath = “/logs/”,
filename = “userLog”
}
},
securityLog = {
class=“coldbox.system.logging.appenders.FileAppender”,
properties = {
filepath = “/logs/”,
filename = “securityLog”
}
}
}
// Root Logger
,root = { levelMin=‘FATAL’, levelMax=‘ERROR’, appenders=“coldboxTracer” }
// categories
,categories = {
models.UserService = { levelMin = “INFO”, levelMax = “INFO”, appenders = “userLog” },
modules_app.security = { levelMin = “INFO”, levelMax = “INFO”, appenders = “securityLog” },
handlers.error = { levelMin=‘FATAL’, levelMax = “WARN”, appenders = “coldboxLog” }
}
};
}
}
`
Thx
Pascal
bdw429s
September 14, 2017, 1:55pm
2
Can you show us an example log message from each category. my guess is the logging categories are not what you expect, so they’re hitting the root logger.
Thanks!
~Brad
ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com
`
“Severity”,“Appender”,“Date”,“Time”,“Category”,“Message”
“ERROR”,“COLDBOXLOG”,“09/14/2017”,“16:04:31”,“handlers.Error”,“CFErrorType=expression CFMessage=variable [GENERATEERROR] doesn’t exist …”
“INFO”,“COLDBOXLOG”,“09/14/2017”,“16:04:42”,“models.UserService”,“Update: User with id 10007 {”“department_id"":"“2"”,"“lastName”":"“User”","“firstName”":"“Test”","“user_id”":"“10007"”,"“email”":""test@stepstone.com ”"}"
“INFO”,“COLDBOXLOG”,“09/14/2017”,“16:04:48”,“modules_app.security.handlers.Login”,“Logging out user admin@stepstone.com ”
`
The “Appender” is different in each file (COLDBOXLOG, SECURITYLOG or USERLOG) but otherwise they are identical
Thx
bdw429s
September 14, 2017, 6:34pm
4
Hmm, that all looks in order to be honest. At this point I’d try one of two things:
Simply your config by reducing to one appender and one category to test and see if it works then
Dig into the LogBox code with dump/aborts and start tracing the sucker through to see where it’s going wrong.
Maybe start with the first and confirm that your loggers that you’re using have the correct category that you expect. log.getCategory()
Thanks!
~Brad
ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com
Hi Brad,
Thanks for the input. I started debugging and found the issue. It is in the definition of the categories. I need to put quotes around category names if they contain dots. Otherwise it wil create nested keys that won’t come up in the hierarchy lookup and I get the config from the root logger.
So the solution was
`
,categories = {
“models.UserService” = { levelMin = “INFO”, levelMax = “INFO”, appenders = “userLog” },
“modules_app.security” = { levelMin = “INFO”, levelMax = “INFO”, appenders = “securityLog” },
“handlers.error” = { levelMin=‘FATAL’, levelMax = “WARN”, appenders = “coldboxLog” }
}
`
Thx for your time
Pascal
bdw429s
September 15, 2017, 2:56pm
6
Oh man, tricky tricky! Good catch and I’m glad it’s working for you now!
Thanks!
~Brad
ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com