When you create a new grails application, the default logback.groovy file (and almost every logback.groovy example, even Mr. Haki's example ) contains the following code, which I simplified to focus on the relevant part:
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 cause errors to be output to the stacktrace.log file.
The @JeffScottBrown answer contains the following Bootstrap.groovy file to check if there was an entry on the stack, as expected:
class BootStrap { def init = { servletContext -> log.error 'this is a new error' } def destroy = { } }
Using this boot file, running grails will not exit build/stacktrace.log .
If you remove the StackTrace and add FULL_STACKTRACE to the root log:
root(ERROR, ['STDOUT', 'FULL_STACKTRACE']
you will get output to the stacktrace.log file.
Alternatively, rename the StackTrace to grails.app.init.Bootstrap (thanks to @JeffScottBrown for this line):
logger 'grails.app.init.BootStrap', ERROR, ['FULL_STACKTRACE'], false
and you will get the result in stacktrace.log
This observation makes me think that the StackTrace is not doing anything. I am also convinced that any registrar not named for the package does not work.
As a result of all this, my question is:
- Does logback work for nameless loggers not related to a package / class?
- If so, why
StackTrace the default logback.groovy not output to the stacktrace.log file?
EDIT:
- The main problem for me is that the
StackTrace seems completely unnecessary, so why is it included in the file by default?
Second edit:
Another way to confirm this is to make only the logger StackTrace write to the STDOUT application, and watch the stack stacks disappear from the console when an exception is thrown:
logger("StackTrace", ERROR, ['STDOUT','FULL_STACKTRACE'], false) root(ERROR, [])