Skip to content

Instantly share code, notes, and snippets.

@akerekes
Created September 17, 2013 12:01
Show Gist options
  • Save akerekes/6593421 to your computer and use it in GitHub Desktop.
Save akerekes/6593421 to your computer and use it in GitHub Desktop.
Extension to Spring's Log4jConfigListener that uses log4j.configuration system property to read the log4j configuration from. If not specified falls back to the Spring's original behavior
package hu.ka.log4j;
import org.springframework.util.Log4jConfigurer;
import org.springframework.web.util.Log4jConfigListener;
import javax.servlet.ServletContextEvent;
import java.io.FileNotFoundException;
public class SystemPropertyLog4jConfigurer extends Log4jConfigListener {
@Override
public void contextInitialized(ServletContextEvent event) {
if (System.getProperty("log4j.configuration") != null) {
try {
Log4jConfigurer.initLogging(System.getProperty("log4j.configuration"));
} catch (FileNotFoundException e) {
System.err.print(e.getLocalizedMessage());
super.contextInitialized(event);
}
} else {
super.contextInitialized(event);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment