grailslogbackgrails-3.1apache-commons-logging

In Grails 3.1.x, how do I configure grails logging to include the class name in the logging statement?


The class that gets printed is the logger's class, not the class that contains the log statement.

logback pattern:

pattern = "%date{ISO8601} [%level] %class{100} %msg%n"

Calling logger in MyController.class:

log.info("Some message);

results in

2017-03-21 19:06:50,824 [INFO] org.apache.commons.logging.Log$Log$info$0 Some message

There is a very similar problem in the Play framework, but the solution is Play specific: https://stackoverflow.com/a/28820410/258896

I tried to explicitly get the logger, but it made no difference in the output.

static Logger log = LoggerFactory.getLogger(MyController.class)

Using:

Grails 3.1.14


Solution

  • Try:

    pattern = "%date{ISO8601} [%level] %logger{0} %msg%n"
    

    Explanation of value in brackets here.