All app logs going into same log4j log file - maven

(might be co-incidence) but this problem is happening after we switched from Ant builds, to Maven.
(server is Weblogic 10.3.5)
We have several apps, each with its own log4j.properties, and each was logging into its own app.log. However, after the Maven builds, all the apps are logging into one single log file. It appears that the first app that we deployed is somehow taking precedence and log4j is writing into that file only.
In the Maven setup, log4j.properties is under src/main/resources. Here's one example of one of our log4j.properties:
log4j.rootLogger=INFO, stdout, logfile
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=logs/stat-calc.log
log4j.appender.logfile.MaxFileSize=4096KB
log4j.appender.logfile.MaxBackupIndex=7
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
Has anyone come across this problem?

This is likely a WebLogic classloading issue. We have solved this in the past by adding a META-INF/weblogic-application.xml file with a format something like this: :
<?xml version='1.0' encoding='UTF-8'?>
<weblogic-application xmlns="http://www.bea.com/ns/weblogic/100"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<prefer-application-packages>
<package-name>org.apache.log4j.*</package-name>
</prefer-application-packages>
</weblogic-application>
This works for ear files. For wars, you need a WEB-INF/weblogic.xml:
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>

Related

Unable to write application logs using externalized Log4j2 XML configuration using Red Hat EAP 7.1.5

I have an application made of Spring Boot WAR packages that need to be migrated to Red Hat EAP 7.1.5.
In my current setup I do the following:
Each WAR has a dedicated log4j2 XML per environment.
This XML file name is defined in the web.xml
The folder containing the log4j2_xxxx.xml is added to the classpath in the JVM startup script.
The WARs are distributed across multiple run-time instances, with a possibility of one run-time hosting more than one WAR.
I would like to replicate the same using EAP. I do see the external log4j2 XML configuration being successfully loaded, however do not see any log statements being written at all.
I am using the following dependencies for packaging log4j2
org.springframework.boot.spring-boot-starter-log4j2 (version 1.5.7)
org.apache.logging.log4j.log4j-web (version 2.10.0)
I have tried the following:
Define a custom module under $JBOSS_HOME/modules/
Add the log4j2 XML in the same folder.
Refer this as global-module in standalone.xml
When I deploy a WAR I can see that the expected log file is created, which means the log4j2 XML configuration is being read successfully. However no logs get written at all in the application log file.
I have tried to get past this by defining a jboss-deployment-structure XML as follows:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.log4j" />
<module name="org.jboss.log4j.logmanager" />
<module name="org.jboss.logging" />
<module name="org.jboss.logging.commons.logging" />
<module name="org.jboss.logging.jul-to-slf4j-stub" />
</exclusions>
<exclude-subsystems>
<subsystem name="logging"/>
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
This results in the application logging being removed from the default JBOSS log (server.log) altogether but it does not write the logs to the designated log as well.
I would expect all the logging being done within the application to be written into the file defined by the external log4j2 XML configuration. Any idea what I am missing?

Spring Boot and Logging with External Tomcat only outputs startup log

My Spring boot 2 app is not showing any log message when is running. I can only see the startup log. This app is deployed as WAR in the production server and I configured the log to output to a file:
logging.file = app.log
logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
logging.pattern.console= %d{yyyy-MM-dd HH:mm:ss} - %msg%n
In my local I can see whatever debug message I include in my code but in the server I can't. I only see the application startup trace.
My config to generate the file is the provided by official guideance. And the tomcat dependency in the app.war:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Do you have any idea of what is happening? It is strange. The log file is generating in the server ( we deploy it in a docker container ) but after the app is running, no more log is output to the file.
By default Spring Boot logs on INFO level, which should include ERROR.
As per Spring boot logging guide 79.1.1 Configure Logback for File-only Output
If you want to disable console logging and write output only to a file, you need a custom logback-spring.xml that imports file-appender.xml but not console-appender.xml, as shown in the following example:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>
You also need to add logging.file to your application.properties which you have alraedy added.

logback.xml change configuration at runtime

is it possible to change the configuration of the logback.xml at runtime with an external file? I dont want to change it programatically. I am using spring boot 1.5
Thanks in advance!
Use logging.config property. Can be a file relative to current working directory or an absolute path.
Option can be passed as argument when running a fat jar (with --logging.config=) or as environment variable (i.e. LOGGING_CONFIG=).
Logging levels can be set dynamically during runtime with actuator, see: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/actuator-api/html/#loggers.
For a logback config file to get you started, see:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.web" level="DEBUG"/>
</configuration>
From Configure Logback for Logging.

JBoss 7 EAP Application Specific Logging with Shared Modules

Maybe I am just completely missing something but I am trying to configure log4j in JBoss 7 EAP with the main goal of isloating application ( WAR ) log messages to unique files.
Our environment has Spring ( 3.X ) configured as a module, and each WAR ( let's call them WAR A and WAR B ) has its own jboss deployment descriptor for Spring as well as a log4j.xml.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
<module name="org.springframework.spring" slot="3.2" meta-inf="export" export="true" />
</dependencies>
</deployment>
</jboss-deployment-structure>
log4j.rootLogger = INFO, FILE
log4j.category.org.springframework=DEBUG
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.File=${jboss.server.log.dir}/webapp_a.log
log4j.appender.FILE.ImmediateFlush=true
log4j.appender.FILE.Threshold=debug
log4j.appender.FILE.Append=true
log4j.appender.FILE.DatePattern='.' yyyy-MM-dd-a
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d %-5p (%-6t) [%X{IP}] [%c] %m%n
Each application creates its own log files, however all the Spring logs are written to the JBoss server.log, and not the application specific log as I would expect. The idea is I would like to see only the spring logs that are relevant to the application in its log file
Am I missing something completely obvious, or really just not understanding how the classloading is working in JBoss 7 where this isn't even possible. Thanks
This is because you have Spring installed as a module. Modules log via the system log context which is configured via the logging subsystem.
Since the org.springframework.spring uses it's own class loader you really wouldn't want the org.springframework.spring module to log with an applications log context. The reason is any static loggers would be configured on whichever application configures the logger first.

Glassfish and Spring Boot: .war re-deployment failed

I am trying to deploy an application build from https://github.com/spring-guides/gs-convert-jar-to-war to local glassfish4. And it delpoys well for the first time (if I can call some exceptions from the framework good behaviour). At least, I can open the project's index page in browser.
But if I try to undeploy it and re-deploy, or just overwrite .war file in autodeploy directory, deployment fails. And nothing seems to be added to glassfish log file.
The projects I published from eclipse using some its mechanisms deployed and re-deployed successfully.
Here is the log with related contents:
http://pastebin.com/zSeMw5tC
What can be the problem?
I did some experiments with Glassfish a while ago. The CDI implementation is really broken IMO (it shouldn't load classes to scan them for annotations), but the apps I tried worked on GF 4 if there is a WEB-INF/classes/META-INF/beans.xml containing
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd"
bean-discovery-mode="none">
<scan>
<exclude name="org.springframework.**" />
<exclude name="org.apache.**" />
<exclude name="com.google.**" />
</scan>
</beans>
Nothing I did ever worked in GF 3 (older CDI spec and no way to exclude things I think).

Resources