log4j2 behaviour different between tomcat 8.5.83 and 8.5.39 - tomcat8.5

We have our web app running on tomcat 8.5.39. This app is using log4j2 correctly, applying a system property before log4j2 starts to indicate the log4j.xml configuration file. Something like:
System.setProperty("log4j.configurationFile", "/opt/ventusproxy/logs");
Now we have migrated to tomcat 8.5.83, and after this our webapp is not able to find the configuration file. Asking the log4j team, and after checking log4j debug file, it seems that, for any reason, log4j2 is starting before we set the previous system property.
We also tried 8.5.79 with the same result.
Is there any configuration change that we are missing between 8.5.39 and a later tomcat version that breaks the way log4j2 was working into our webapp until now?
Thanks,
Joan.

Related

Application specific logs not getting generated in JBoss EAP 7.3.0

I have developed an application using Spring Boot and deployed that in JBoss EAP 7.3.0server. The application is writing the application specific logs in a separate log file (not server.log of JBoss) and we are using log4j for logging. The name and path where the lo would be generated is specified in log4j.properties placed in the classpath of the application. This setup is working correctly and logs are getting generated in one of our environments but logs are not getting generated in another environment. We are suspecting that the logger is not defined in JBoss in the environment where the logs are not getting generated. Can anyone please say from where to check the logger configuration of JBoss and how to ensure whether all the configurations are correct so that the logs will get generated?
Note: The JBoss server.log is getting generated correctly in all the environments.

Spring Log4j2 xml file location

using Spring 2.0.5 with Log4j2
Have found works as expected if I place the file log4j2.xml in the resources folder.
However, have found the log4j2 option of monitorInterval="60" to be super useful as if some production issue can increase logging on some class without a restart. However if log4j2.xml is embedded in the jar of course it cannot be modified. so far the best I have been able to do is use 2 copies of log4j2.xml one in the resources and the other in the folder running the jar from.
I can then run:
java -Dlog4j.configurationFile=log4j2.xml -jar myapp.jar
it seems to work the same if started from the maven spring-boot plugin or from Eclipse.
Have tried a number of things such as setting the classpath, the absolute file name etc. but no luck
My question is how can I remove the log4j2.xml file from the resources folder and only specify it on the command line when starting spring?
I am not entirely clear on your question but I can provide the following information which I hope addresses it:
Log4j 2.12.0 added support for Spring Cloud Config and enhanced the support for Spring Boot. As of that version you can include a file named log4j2.system.properties and place any system properties you want defined there. They will be set before Log4j initializes. So you can specify the full URL to the configuration there if you want instead of the command line. You can also add the definition to a file named log4j2.component.properties.
The support for Spring Cloud Config allows you to place the configuration in your Spring Cloud Config server. See Spring CLoud Config support for more details.
Spring Boot initializes logging at least 3 times. The first is usually because the SpringApplication class declares a Logger so logging is initialized before anything else happens. The configuration for that will use "normal" log4j 2 initialization. After that Spring influences how logging initialization occurs primarily because Spring Boot sets the class path to include the jars inside BOOT-INF/lib directory inside your Spring Boot jar.
By using one of the configuration options I outlined above you can move the logging configuration outside of your application and you should not require a logging configuration in the resources directory. In fact, if you look at the sample Spring Cloud Config Application in Log4j you will see it does not include a configuration file in it.

Spring Boot - logging configuration from JBoss

I'd like to know if there is a way to configure Spring Boot logging using JBoss standalone.xml or domain.xml configuration. For now I ended up with two empty files log4j.properties and log4j-file.properties under org\springframework\boot\logging\log4j package in mvn resources in WAR file and it looks like now my logging configuration in domain.xml works because I've overriden default spring-boot log4j configuration.
But there must be a better way to do this instead of this stupid hack. Keep in mind that I don't want to provide external log4j properties file and set it for one of the property in application.properties but I want to use jboss logging system configuration.
EDIT
Strange thing but when I updated Spring Boot to version 1.4.0 then JBoss intercepts the logs and log them only to the file and I don't have logs on the stdout anymore even without custom log4j configuration.

Spring Boot environment aware log4j properties

I try to use environment aware log4j properties files in Spring Boot application, for example, log4j.properties is used for development and log4j-uat.properties for UAT environment as showed in picture.
following Extern log4.properties file with Spring Boot, I added logging.config=log4j-uat.properties to application-uat.properties and get exception said cannot find that properties file.
following https://github.com/spring-projects/spring-boot/issues/1348, I added parameter when starting the application as java -jar logger-server.jar --spring.profiles.active=uat -Dlogging.config=classpath:log4j-uat.properties. However, it seems that the uat log4j properties is always overwritten by the default log4j properties.
Could anyone please advise me how to make Spring Boot pick up the log4j properties files for different environments?
Thanks,
Sean

Spring, log4j and JBoss4

I'm running JBoss 4.2.3.GA, and have a web app that uses Spring and Log4j. I've set up Spring's Log4jConfigurer, but am having a problem since JBoss's log4j file is not on the classpath. It's at jboss.home/server/defaul/conf/jboss-log4j.xml. So, without hard-coding the path in Log4jConfigurer, how can I get Spring to use JBoss's log4j file?
You don't generally modify JBoss's log4j config via the applications, that's a route to madness. JBoss uses a shared configuration amongst all apps.
You can, however, programmatically alter log4j's runtime configuration, such as adding custom appenders or loggers. This isn't what Spring's Log4jConfigurer is for, however - you use that to configure a standalone log4j config.
Do answer your question: JBoss usually sets additional system properties that point to the server directory and configuration directories. You should be able to access these from your application or let them be resolved from the spring contexts.
In your case, it should be ok to access ${jboss.server.home.dir}/conf/jboss-log4j.xml
As skaffman correctly pointed out in a comment, there is no need to configure Spring to read JBoss' log4j configuration unless you have otherwise adapted something in the packaging. You will only have to take care that no log4j.[properties,xml] lies somewhere in the root of the classpath or that a component tries to configure Log4J "manually".
Hope this could help,
Kariem

Resources