persa
persa

Reputation: 37

Grails logging from grails-app/utils

I would like to log from utils classes in grails-app/utils folder.

Does anyone know what package should I put in Config.groovy log section ? I tried my own package "com.company" and "grails.utils" but no one works.

Many thanks

Upvotes: 1

Views: 507

Answers (2)

Burt Beckwith
Burt Beckwith

Reputation: 75671

A log field is added to all Groovy classes - this happens during compilation via an AST transform. If logging doesn't appear to be working, add println log.name in a method that gets executed and you'll see the whole logger name to use in Config.groovy in the console.

As @dmahapatro mentioned, grails-app/utils is not for utility classes. In early versions of Grails the folder was added with the expectation that it would contain various artifact types that didn't merit their own grails-app subfolder. No other artifacts beyond codecs were added though, so codecs are the only classes that should be there. Utility classes should always go in src/groovy or src/java - only artifact classes and config files belong under grails-app.

Upvotes: 1

dmahapatro
dmahapatro

Reputation: 50245

Assuming info level logging is required, you can use:

//if logging required for all classes under grails-app/utils
info 'grails.app.utils' 

//if logging required for a particular class under grails-app/utils
info 'grails.app.utils.com.company.SampleUtil' 

Also remember that grails-app/utils is mainly dedicated for codecs and not for utility classes. In case you are looking to add utility classes for the app then it should go under src/groovy or src/java respectively for groovy or java classes.

Upvotes: 1

Related Questions