log4j issue in ear project deployed in weblogic - log4j

I have configured log4j in resources folder of each module in EAR project. EAR contains two WARs and one EJB and one JAR. I deployed EAR in Weblogic which is running in cluster mode.
log4j is not working in Weblogic cluster node.

Log4j requires log4j.properties/log4j.xml for proper configuration. When Log4j loads it looks for either log4j.properties file or log4j.xml. If log4j is not able to locate this file
it will not log at all.
In order to make log4j to work make sure
Log4j.properties/log4j.xml file is in classpath.
All modules/jars/ejbs/war must use the same property/xml file unless otherwise
you need separate log4j configurations for each module.
More than one configuration files either property file or xml will conflict and log4j may will not work as expected.

Related

Do I need to update log4j.properties file if I use the Log4j 1.x bridge (log4j-1.2-api)

I've followed the doc here : https://logging.apache.org/log4j/2.x/manual/migration.html
Also looked at https://logging.apache.org/log4j/2.x/manual/configuration.html#Properties
My existing log4j.properties only uses DailyRollingFileAppender, ConsoleAppender, both of which are under the 'Supported Components', so I shouldn't be forced to convert my log4j.properties file into log4j2.properties format. I'm not accessing methods and classes internal to the Log4j 1.x implementation, as suggested by the document.
For using the bridge, I previously was using both log4j1.compatibility and log4j.configuration, but the document suggests using 'any one' (tried using just one, doesn't work)
I can build my application successfully, however, my application no longer logs anything. What am I missing?
You may want to consider reload4j as a drop-in replacement for log4j 1.x. Initiated by Ceki Gülcü, the original author of Apache log4j 1.x, the reload4j project is a fork of Apache log4j version 1.2.17 with the goal of fixing pressing security issues.
The reload4j project offers a clear and easy migration path for the users who have an urgent need to fix vulnerabilities in log4j 1.2.17.
You don't need to update your properties file.
You can add a log4j2.component.properties file on the class path (in my case, in the same directory as my log4j.properties file) to set the log4j1.compatibility property, like this:
log4j1.compatibility=true
In our case, it only required setting the compatibility property and then it automatically picked up the log4j.properties file that was available on the class path.
Figured it out.
The answer lied in the Automatic Configuration section

Log4j Class missing on Weblogic

I have deployed a war file on Oracle Weblogic. War files contain all the required libraries in WEB-INF/lib. But whenever I am trying to visit my webpage, it gives error of
java.lang.NoClassDefFoundError: org/apache/log4j/Logger.
try adding to weblogic.xml :
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
(Although this may cause secondary issues with JSF jar's.)
The problem is resolved. One of my custom library using log4j, that one was not able to find log4j. So I created the jar including log4j and its working.

Websphere 8.5.3, SLF4j Log4j, Multiple EARs, multiple log files not generating

I have two EARs deployed to Websphere 8.5.3 with different log4j configurations. But the server is only generating one log file. If I deploy the EARs individually, the server is generating the log file , but when both the EARs are deployed only one log file is being generated by the server. I have the slf4j-log4j jars on the class path and one lo4j.properties in each EAR's WAR module.
Can anyone please help me understand whats going on with the Websphere JVM or if I am doing something wrong
log4j.rootLogger=INFO
log4j.logger.com.code.first=INFO,appOne
log4j.appender.appOne=org.apache.log4j.RollingFileAppender
log4j.appender.appOne.Name=ApplicationLogAppender
log4j.appender.appOne.File=/logPath/AppOneLog.log
log4j.appender.appOne.layout=org.apache.log4j.PatternLayout
log4j.appender.appOne.MaxFileSize=10MB
log4j.appender.appOne.MaxBackupIndex=10
log4j.appender.appOne.layout.ConversionPattern=%d %-5p %t - %m%n
log4j.appender.appOne.Threshold=DEBUG
log4j.appender.appOne.Append=false
log4j.rootLogger=INFO
log4j.logger.com.code.second=INFO,appTwo
log4j.appender.appTwo=org.apache.log4j.RollingFileAppender
log4j.appender.appTwo.Name=ApplicationLogAppender
log4j.appender.appTwo.File=/logPath/AppTwolog.log
log4j.appender.appTwo.layout=org.apache.log4j.PatternLayout
log4j.appender.appTwo.MaxFileSize=10MB
log4j.appender.appTwo.MaxBackupIndex=10
log4j.appender.appTwo.layout.ConversionPattern=%d %-5p %t - %m%n
log4j.appender.appTwo.Threshold=DEBUG
log4j.appender.appTwo.Append=false
This:
I have the slf4j-log4j jars on the class path
Does that mean the same log4j JAR is shared between the applications? There may be a problem that the log4j classes are loaded just once and shared between the applications. Can you try putting the log4j JAR in each web module WEB-INF/lib folder? That will give each of the web modules its own load of the log4j classes and may resolve the problem. (Also, since log4j classes are also used by the server, make sure to have the web modules load classes from themselves first.)
Thomas Bitonti, IBM WebSphere Application Server Development

log4j multiple configuration files

I have couple of projects embedded in a web app as jars. Each project has a log4j.properties file. When the web app is deloyed, which configuration file gets used and how to override the configurations in log4j.xml in a jar file. The jars are not web projects. They are more like service layer code. What is the order in which the log4j.properties file is loaded in the below scenario
Web-project
classes
log4j.properties
ProjectB.jar
com
log4j.properties
ProjectC.jar
com
log4j.properties and so on.
If your jars are separate web applications, each web application should use the one it first finds on the classpath (WEB-INF/classes).
You can pass a -Dlog4j.configuration=path_to_file setting to e.g. the tomcat startup to make sure that it uses the one you intend it to use.
However, this would then to my understanding and knowledge be the one that tomcat will use for every webapp that is deployed.
Question here is how you deploy your apps. Either all web applications in one tomcat in which case you probably want each web application to use a different log4.properties (or log4j.xml) or in the case where you specify one to tomcat, it should use the one you specify.
What it boils down to as far as i know: Either the first one found on classpath (remember: each web-app has it's own classpath) or the one you specify via the -D setting.
Just found this reference which i think nicely summarizes the main concepts of logging in tomcat and webapps deployed in tomcat: http://wiki.apache.org/tomcat/FAQ/Logging
If you need even more control over the log4j logging, you can resort to coding the log4j configuration in java. However, this would mean that you have to modify the source code and add code into it, which relates to infrastructure and relates deployment details to your application (not so nice).
If you set additivity to false in common packages at ProjectA, ProjectB and WebProject your log will not duplicate.
log4j.additivity.[logged package] = false
For example:
log4j.properies -> Project A, Project B
log4j.additivity.org.spring.framework = false
All org.spring.framework log will come from WebProject ignoring ProjectA and ProjectB.

jboss7 + same log4j configuration for different apps

I want to deploy some different applications using one jboss (jboss as 7). Can anyone make it clear for me if its possible to set one log4j configuration (log4j.xml) for multiple wars and ears or i'll have to put a copy of configuration into each archive?
Or maybe someone can suggest a differeng logging engine, more native to jboss7?
log4j configuration is always global to runtime. ie. A JBoss instance can't have multiple log4j configuration. log4j can be initialized or reinitialized with a single config file. it can be a simple properties file or a XML incompliance with log4j.dtd packaged with log4j*.jar. start the jboss instance with -Dlog4j.configuration=/anypath/log4jconfig.xml
I do not believe there is a way to configure log4j globally. JBoss AS7 uses JBoss Logging for it's log provider. You can configure the logging subsystem is in the standalone.xml or the domain.xml depending on if you're running in standalone or domain mode.
The documentation is not greatest unfortunately, but if you install the jboss-as-logging_1_1.xsd in your IDE you can get auto-complete. All the schemas are located in the docs/schema under the installed directory.

Resources