When you create a new grails application, the default logback.groovy file (and almost every example of a logback.groovy, even Mr Haki's example) contains the following code, which I have simplified to focus on the relevant piece:
root(ERROR, ['STDOUT'])
appender("FULL_STACKTRACE", FileAppender) {
file = "build/stacktrace.log"
append = true
encoder(PatternLayoutEncoder) {
pattern = "%level %logger - %msg%n"
}
}
logger("StackTrace", ERROR, ['FULL_STACKTRACE'], false )
However, following this approach does not result in errors being output to the stacktrace.log file.
@JeffScottBrown's answer contained the following Bootstrap.groovy file to test if the stacktrace was logging as expected:
class BootStrap {
def init = { servletContext ->
log.error 'this is a new error'
}
def destroy = {
}
}
With that bootstrap file, running the grails application will not produce any output into build/stacktrace.log
.
If you remove the StackTrace
logger, and add FULL_STACKTRACE
to the root logger:
root(ERROR, ['STDOUT', 'FULL_STACKTRACE']
you will get output into the stacktrace.log.
Alternatively, rename the StackTrace
logger to grails.app.init.Bootstrap
(thanks to @JeffScottBrown for this line):
logger 'grails.app.init.BootStrap', ERROR, ['FULL_STACKTRACE'], false
and you will get output into the stacktrace.log
This observation leads me to believe that the StackTrace
logger doesn't do anything. I further am led to believe that any logger not named for a package doesn't work.
As a result of all this, my question is:
- Does logback work for non-package/class named loggers?
- If so, why does the
StackTrace
logger in the defaultlogback.groovy
not result in output to stacktrace.log?
EDIT:
- The main issue for me is that the
StackTrace
logger seems completely unnecessary, so why is it included in the default file?
Second Edit:
Another way to confirm this is to make only the StackTrace
logger write to the STDOUT
appender, and watch stacktraces disappear from the console when you throw an exception:
logger("StackTrace", ERROR, ['STDOUT','FULL_STACKTRACE'], false)
root(ERROR, [])
build
directory of the grails project. – SherlyFULL_STACKTRACE
appender, namely theStackTrace
logger defined as:logger("StackTrace", ERROR, ['FULL_STACKTRACE'], false )
? If you have any other logger usingFULL_STACKTRACE
, you are bypassing the line I believe to be useless. – Obeisance