Pregunta

I'm writing a Grails plugin that will impose very specific log4j settings (in its own log4j.xml), and I would like to configure it such that an app which uses this plugin is forced to use the plugin's log4j configuration (instead of any log4j configs that the app itself has defined).

For example, let's say I want the plugin to force all downstream Grails apps to log to a file called /var/log/fizz.log. How could I make this work?

Update: And if it's not possible for the plugin to override the app that uses it, then at the very least I need the app to be able to use the plugin's log4j config without having to define its own.

¿Fue útil?

Solución

First, the application configuration settings will always trump the plugin settings. You can't avoid that (as far as I know).

However, you can always remove the log4j configuration from the application's config.groovy and make your plugin wire in the log4j configuration within the doWithSpring event of the plugin's lifecycle. This will ensure that the plugin is responsible for configuring log4j.

I will assume you don't need any help wiring up the log4j.xml portion since you didn't ask about that. Just in case, that might look something like this:

MyLoggingPlugin.groovy

...
def doWithSpring = {
  ...
      log4jConfigurer(org.springframework.beans.factory.config.MethodInvokingFactoryBean){
        targetClass = "org.springframework.util.Log4jConfigurer"
        targetMethod = "initLogging"
        arguments = "path/to/log4j.xml"
      }
  ...
}
...
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top