jboss7 + same log4j configuration for different apps - log4j

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.

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

Why log4J not working after adding apache CXF?

I have developed small web application using JSF, and i add log4j to handle logging. Everything works perfectly until i implement add web service in my web application. After implement webservice using apache CXF I'm not getting any logs in my log file, but can get logs in eclipse console. I don't know why, it behave like that? My log file simply show messages like
i'm using jdk1.5, log4j 1.2.15 and CXF 2.6.11. Also i was tried some solutions from apache to use log4j instead of cxf default logger. please refer http://cxf.apache.org/docs/debugging-and-logging.html#DebuggingandLogging-LoggingMessages
But recommended solutions are not worked for me. How can i solve this issue?
It is possible that CXF introduces another log mechanism which means adds a yet another logging mechanism, or the imported versions of slf4j/log4j are not compatible.
I would recommend you to check the CXF pom file, and exclude all the log4j/slf4j jar files.
As #Arash said, remove log4j from classpath (if present). Also add the file META-INF/cxf/org.apache.cxf.Logger to the classpath with the following content:
org.apache.cxf.common.logging.Slf4jLogger
Reference: Using SLF4J Instead of java.util.logging
Problem was solved by removing slf4j-jdk14.jar from CXF. Actually Problem is "Class path contains multiple SLF4J bindings". So i removed CXF log4j binding. Now it's working perfectly. Thanks for all.

log4j issue in ear project deployed in weblogic

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.

how to define multiple log4j configs with Jetty server in web.xml

Here's what I want to do:
- being able to have separated log4j.properties for each different deployment "war"
- being able to define in ant build, or web.xml, using system parameter on which log properties to use.
My project setup is Jetty with Jersey as REST API, without Spring.
I've done some research and it turns there are other Spring solutions to set in webl.xml but I'm not using spring.
I also know Jetty is using slf4j but if switching to slf4j, would I be able to do this more easily?
What would be a best way to solve this, so that in web.xml or ant build, log4j config can be customized defined?
Thanks a lot!
EDIT:
I figured that I can start another servlet with some init-param defined. Then on a separated HttpServlet implementation to set the PropertyConfigurator.configure([name of the log4j config]);
Is this adding one more servlet an ideally way of handling this?
Lots of different ways to handle this.
Since your mission is not different logging per Servlet, or per Webapp...I wouldn't solve the problem in the servlet or webapp locations but at the server level. To me, you want to log all this information to the correct place, not just all the information once the servlet has been deployed. To this end, I would enable the slf4j-api support in jetty and then look into the best way to handle that from the slf4j side of things. With that you can use whatever logging framework you want, slf4j-simple, log4j or logback..whatever you like.
Alternatively, if you really want to avoid the server side of logging, I supposed you could just use a log4j.properties file in the resources directory and then on jetty startup on the command line serve out a different resources directory. Figure out what options you want and startup with:
java -jar start.jar OPTIONS=Server,jmx,jsp,resources-[dev,qa,prod]
cheers

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.

Resources