Grails Goodness: Set Log Level for Grails Artifacts
Grails Goodness: Set Log Level for Grails Artifacts
Join the DZone community and get the full member experience.
Join For FreeGet the Edge with a Professional Java IDE. 30-day free trial.
A good thing in Grails is that in Grails artifacts like controllers and services we have a log
property to add log statements in our code. If we want to have the output of these log statements we must use a special naming convention for the log names. Each logger is prefixed with grails.app
followed by the Grails artifact. Valid artifact values are controllers
, services
, domain
, filters
, conf
and taglib
. This is followed by the actual class name. So for example we have a controller SampleController
in the package mrhaki.grails
then the complete logger name isgrails.app.controllers.mrhaki.grails.SampleContoller
.
The following sample configuration is for pre-Grails 3:
// File: grails-app/conf/Config.groovy ... log4j = { ... info 'grails.app.controllers' debug 'grails.app.controllers.mrhaki.grails.SampleController' info 'grails.app.services' ... } ...
In Grails 3 we can use a common Logback configuration file. In the following part of the configuration we set the log levels:
// File: grails-app/conf/logback.groovy ... logger 'grails.app.controllers', INFO, ['STDOUT'] logger 'grails.app.controllers.mrhaki.grails.SampleController', DEBUG, ['STDOUT'] logger 'grails.app.services', INFO, ['STDOUT'] ...
Written with Grails 2.5.0 and 3.0.1.
Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.
Published at DZone with permission of Hubert Klein Ikkink , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}