I have a grails application, deployed to tomcat, that is using log4j. I would like to be able to update /webapps/WEB-INF/classes/log4j.properties in tomcat, and then have the application dynamically pickup the changes without requiring a restart. I haven't had any luck finding a good way to do this. What I have figured out is:
I can retrieve a file as a stream:
Thread.currentThread().getContextClassLoader().getResourceAsStream("log4j.properties")
Unfortunately this is the class loaded during startup, and I'm not sure if/how I can force it to update from the actual file. If that worked I could read each property and use:
Logger.rootLogger.loggerRepository.getLogger(<key>).level = <new log level>
I've seen things about LogManager.resetConfiguration()
but that doesn't seem to help either.
Also, this is how I setup log4j in resources.groovy
beans = {
// Setting up external configuration for log4j
log4jConfigurer(org.springframework.beans.factory.config.MethodInvokingFactoryBean) {
targetClass = "org.springframework.util.Log4jConfigurer"
targetMethod = "initLogging"
arguments = ["classpath:log4j.properties"]
}
}
I'm not interested in using the configureAndWatch
approach as I've read about its vulnerabilities.
I see that there are XML and JSON properties you can use for log4j, and I'm just using a plain *.properties file, and I'm not sure if that is part of the problem.
Any tips would be greatly appreciated, thanks in advance!