Skip to content

Commit

Permalink
Fix for GRAILS-8010 [Duplicated log message if any appenders named in…
Browse files Browse the repository at this point in the history
… root{...} block]
  • Loading branch information
lhotari committed Sep 26, 2011
1 parent 944896b commit 051a0b5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
Expand Up @@ -15,16 +15,21 @@
*/
package org.codehaus.groovy.grails.plugins.log4j

import java.util.Collection;
import java.util.Map;

import grails.util.BuildSettings
import grails.util.BuildSettingsHolder
import grails.util.Environment
import groovy.lang.Closure;

import org.apache.commons.beanutils.BeanUtils
import org.apache.log4j.Appender
import org.apache.log4j.ConsoleAppender
import org.apache.log4j.FileAppender
import org.apache.log4j.HTMLLayout
import org.apache.log4j.Level
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger
import org.apache.log4j.PatternLayout
import org.apache.log4j.RollingFileAppender
Expand Down Expand Up @@ -56,6 +61,27 @@ class Log4jConfig {
Log4jConfig(ConfigObject config) {
this.config = config
}

public static void initialize(ConfigObject config) {
if (config != null) {
LogManager.resetConfiguration();
Object o = config.get("log4j")
Log4jConfig log4jConfig = new Log4jConfig(config)
if (o instanceof Closure) {
log4jConfig.configure((Closure<?>)o);
}
else if (o instanceof Map) {
log4jConfig.configure((Map<?, ?>)o);
}
else if (o instanceof Collection) {
log4jConfig.configure((Collection<?>)o);
}
else {
// setup default logging
log4jConfig.configure();
}
}
}

def methodMissing(String name, args) {
if (APPENDERS.containsKey(name) && args) {
Expand Down
Expand Up @@ -46,11 +46,7 @@ class LoggingGrailsPlugin {
}

def onConfigChange = { event ->
def log4jConfig = event.source.log4j
if (log4jConfig instanceof Closure || log4jConfig instanceof Collection || log4jConfig instanceof Map) {
LogManager.resetConfiguration()
new Log4jConfig(event.application.config).configure(log4jConfig)
}
Log4jConfig.initialize(event.source)
}

def doWithWebDescriptor = { webXml ->
Expand Down
Expand Up @@ -49,21 +49,7 @@ public void contextInitialized(ServletContextEvent event) {
// create empty app to provide metadata
GrailsApplication application = new DefaultGrailsApplication();
co = application.getConfig();
if (co != null) {
Object o = co.get("log4j");
if (o instanceof Closure) {
new Log4jConfig(co).configure((Closure<?>)o);
}
else if (o instanceof Collection) {
new Log4jConfig(co).configure((Collection<?>)o);
}
else if (o instanceof Map) {
new Log4jConfig(co).configure((Map<?, ?>)o);
}
else {
new Log4jConfig(co).configure();
}
}
Log4jConfig.initialize(co);
}
}
catch (Throwable e) {
Expand Down
Expand Up @@ -15,9 +15,8 @@
*/
package org.codehaus.groovy.grails.plugins.logging;

import groovy.lang.Closure;
import groovy.util.ConfigObject;
import org.apache.log4j.LogManager;

import org.codehaus.groovy.grails.plugins.log4j.Log4jConfig;

/**
Expand All @@ -29,13 +28,6 @@
public class LoggingInitializer {

public void initialize(ConfigObject config) {
LogManager.resetConfiguration();
Object log4j = config.get("log4j");
if (log4j instanceof Closure) {
new Log4jConfig(config).configure((Closure<?>)log4j);
} else {
// setup default logging
new Log4jConfig(config).configure();
}
Log4jConfig.initialize(config);
}
}

0 comments on commit 051a0b5

Please sign in to comment.