Why does stacktrace.log not populate logback in grails 3?

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, [])

+6
grails logback logback-groovy
source share
3 answers

I expect that you will not configure the application to be used correctly.

The following works:

 import grails.util.BuildSettings import grails.util.Environment // See http://logback.qos.ch/manual/groovy.html for details on configuration appender('STDOUT', ConsoleAppender) { encoder(PatternLayoutEncoder) { pattern = "%level %logger - %msg%n" } } root(ERROR, ['STDOUT']) def targetDir = BuildSettings.TARGET_DIR if (Environment.isDevelopmentMode() && targetDir) { appender("FULL_STACKTRACE", FileAppender) { file = "${targetDir}/stacktrace.log" append = true encoder(PatternLayoutEncoder) { pattern = "%level %logger - %msg%n" } } logger("StackTrace", ERROR, ['FULL_STACKTRACE'], false) } logger 'grails.app.init.BootStrap', ERROR, ['FULL_STACKTRACE'], false 

In BootStrap.groovy ...

 class BootStrap { def init = { servletContext -> log.error 'this is a new error' } def destroy = { } } 

This error is displayed in stacktrace.log .

EDIT to ask new questions:

Does logback work for nameless loggers not related to a package / class?

Yes.

If so, why by default does the StackTrace logger in loglog.groovy not lead to output to the stacktrace.log file?

The StackTrace logger causes the output to be written to the stacktrace.log file for all loggers associated with the corresponding application.

0
source share

change

 logger("StackTrace", ERROR, ['FULL_STACKTRACE'], false ) 

to

 logger("grails.app", INFO, ['FULL_STACKTRACE'], false) 

will write all the logs in grails-app in stacktrace.log

0
source share

Your log statement in Bootstrap.groovy:

 log.error 'this is a new error' 

writes a regular ERROR message to a logger named grails.app.init.yourapp.BootStrap . It is not logged in the StackTrace . The FULL_STACKTRACE application is for unfiltered stacks. They are written in a frame to the StackTrace .

If you replace

 log.error 'this is a new error' 

from

 throw new RuntimeException("foo") 

you will see that the full stack line is written to the stacktrace.log file

0
source share

All Articles