从Grails BootStrap.groovy和插件描述符发送日志消息 [英] Sending log messages from Grails BootStrap.groovy and plugin descriptors

查看:229
本文介绍了从Grails BootStrap.groovy和插件描述符发送日志消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将Fixture模块引入到我的Grails应用程序中时,我无法找到如何从应用程序的主BootStrap.groovy和我的插件的初始化代码发送日志消息。


<在Grails 2.2.4中:



log记录器被注入到应用程序的主BootStrap中。 groovy和插件的描述符(例如:FooGrailsPlugin.groovy)

应用程序的BootStrap.groovy中的记录器有一个名称,例如grails.app.BootStrap在配置中追加grails.app记录器将允许显示通过这个记录器发送的消息。



插件描述符中的记录器没有包前缀,完全按照描述符类命名,但没有groovy扩展名。例如:FooGrailsPlugin,因此默认注入记录器启用日志消息并不那么容易。如果您将包定义添加到插件描述符的顶部,它将不会起作用,它不会用于记录器名称的组合。



当然,您可以在插件描述符中手动定义一个记录器(根据您的需要使用包名),如下所示:

  private static final log = LogFactory.getLog(yourapp.foo.FooGrailsPlugin)

在此之后,您可以启用yourapp.foo记录器,您将看到通过插件描述符手动定义的记录器发送的消息。


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.

解决方案

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:

private static final log = LogFactory.getLog("yourapp.foo.FooGrailsPlugin")

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.

这篇关于从Grails BootStrap.groovy和插件描述符发送日志消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆