When I was introducing the Fixture module into my Grails application, I had trouble finding out how to send log messages from the application's main BootStrap.groovy and from the initialization code of my plugins.
相关问题
- I want to trace logs using a Macro multi parameter
- Error message 'No handlers could be found for
- convert logback.xml to log4j.properties
- Django management command doesn't show logging
- Grails External Configuration. Can't access to
相关文章
- how do I log requests and responses for debugging
- Call non-static methods on custom Unity Android Pl
- How to obtain the enable admission controller list
- Android Studio doesn't display logs by package
- Stacktrace does not print in Glassfish 4.1 Cluster
- Out of curiosity — why don't logging APIs impl
- Grails: How to make everything I create Upper Case
- Laravel log file based on date
I use the following log4j config in
Config.groovy
The only change you should need to make is to set
packageRoot
to the root package of your app. The name/namespace of the logger that is assigned toBootStrap.groovy
isgrails.app.conf.BootStrap
, so including this inappNamespaces
ensures that it will log at the default level for the application (debug in the example above).You don't have to do anything to get a logger instance in
BootStrap.groovy
, one is already provided by Grails with the namelog
, e.g.In Grails 2.2.4:
The "log" logger is injected into the application's main BootStrap.groovy and into the plugin's descriptor (e.g.: FooGrailsPlugin.groovy)
The logger in the app's BootStrap.groovy has a name like "grails.app.BootStrap" so by enabling the appending of the "grails.app" logger in the configuration will allow displaying the messages sent through this logger.
The logger in the plugin descriptors has no package prefix, and named exactly as the descriptor class but without the groovy extension. E.g.: "FooGrailsPlugin", so it is not so easy to enable the log messages by the default injected logger. It doesn't help if you add a package definition into the top of plugin descriptor, it will not be used in the composition of the name of the logger.
Naturally, you can manually define a logger in the plugin descriptor (using a package name according to your needs) like this:
After this, you can enable the "yourapp.foo" logger in the application and you will see the messages sent through the plugin descriptor's manually defined logger.