File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Websphere and the fly likes Websphere 6.1 - Apache commons logging with log4j does not work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "Websphere 6.1 - Apache commons logging with log4j does not work" Watch "Websphere 6.1 - Apache commons logging with log4j does not work" New topic
Author

Websphere 6.1 - Apache commons logging with log4j does not work

sanker san
Ranch Hand

Joined: Dec 17, 2004
Posts: 53
I'm trying to use Log4j in conjunction with apache commons logging to write to log files. I've placed a commons-logging.properties in the WEB-INF\classes folder. The application uses log4j and writes to log files when running in WSAD5.0. When the application runs in the application server, it uses the default 'org.apache.commons.logging.impl.Jdk14Logger' and not 'org.apache.commons.logging.impl.Log4jLogger'. Could you please help?

commons-logging.properties:-
priority=1
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl

log4.properties
log4j.rootCategory=DEBUG, CONSOLE, LOGFILE

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n

# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=/cust/logs/SLKServices/axis.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.Threshold=DEBUG
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x %L- %m%n
Yogesh Wani
Greenhorn

Joined: Jul 29, 2003
Posts: 6
Put it in the lib folder of the WEB-INF or any folder which is in the classpath.

Regards
Yogesh
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

Apache Commons logging is built into Websphere, so it is loaded from what you might call Websphere's system classloader. That classloader can't see anything in any particular web application, so in particular it can't see the properties file you set up.

Cameron McKenzie has a Websphere classloader link that he regularly posts in this forum, so you could search for that to get more information.
sanker san
Ranch Hand

Joined: Dec 17, 2004
Posts: 53
Paul,
The application uses PARENT_LAST for ear and war modules. Also the priority is set to 1 in the commons-logging.properties. So shouldn't it take the log4jlogger? Is there any other setting that we can do?

The link provided by Cameron McKenzie for Websphere classloader [www.techincalfacilitation.com] is broken.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

There's this article that IBM published about Websphere 5.0 and Commons logging:

http://www-1.ibm.com/support/docview.wss?uid=swg27004610

I tried it and still couldn't make it work. As I recall it did pretty much what you already did, only in a more obscure way.

You said WSAD? The Websphere test environment? That might be slightly different too, the article is about the Websphere server. Good luck.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

Originally posted by sanker san:
The link provided by Cameron McKenzie for Websphere classloader [www.techincalfacilitation.com] is broken.
Looks like the host name is misspelled. Try http://www.technicalfacilitation.com/ instead.
Robert Glover
Greenhorn

Joined: Feb 07, 2004
Posts: 26
I need help with getting log4j working in RAD7. I had to convert yesterday from WSADS 5.1 to RAD7. Using WSADS 5.1 my log4j worked perfectly. But using RAD7 my log4j is totally ignored and none of my logging messages appear at install. Instead, thousands of lines of log4j messages appear that are coming from, among others:

org.apache.commons.digester.Digester, org.apache.struts.tiles.xmlDefinition.XmlDefinition,
org.springframework.beans.factory.support.DefaultListableBeanFactory,
org.apache.commons.beanutils.ConvertUtils

I've been struggling for going on two years trying to get log4j to work in WSADS6 and now in RAD7. My last job used WSADS6 and I never could get log4j to work in it. At my current company using WSADS 5.1 I had perfect logging of log4j.

I wrote a long review of a book about log4j over a year ago which you can read on www.amazon.com at:
http://www.amazon.com/Apache-Log4j-Second-Samudra-Gupta/dp/1590594991/ref=pd_bbs_sr_1/103-0698628-5488656?ie=UTF8&s=books&qid=1179957639&sr=8-1

I've tried all the obvious things with no success to get log4j to work in RAD7. I have the log4j jar file in the lib directory of the dynamic web application. I set the classloader to look at the application first, which is done in the Websphere 6.1 (test) appserver.

Below I have pasted the log4j parameters that I set in web.xml. These worked perfectly in WSADS 5.1 but apparantly are being ignored in RAD7:

<web-app id="WebApp">
<display-name>tuesRoundup</display-name>
< !--<br /> Location of the Log4J config file; either a "classpath:" location<br /> (e.g. "classpath:myLog4j.properties"), an absolute file URL<br /> (e.g. "file:C:/log4j.properties), or a plain path relative to the web application<br /> root directory (e.g. "/WEB-INF/log4j.properties").<br /> -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
< !--<br /> Whether the web app root system property should be exposed, allowing for log file paths <br /> relative to the web application root directory. Default is "true"; specify "false" to<br /> suppress expose of the web app root system property.<br /> -->
<context-param>
<param-name>log4jExposeWebAppRoot</param-name>
<param-value>true</param-value>
</context-param>
< !--<br /> By default, this configurer automatically sets the web app root system property,<br /> for "${key}" substitutions within log file locations in the Log4J config file, <br /> allowing for log file paths relative to the web application root directory.<br /> The default system property key is "webapp.root", to be used in a Log4J config<br /> file like as follows:<br /> log4j.appender.myfile.File=${webapp.root}/WEB-INF/demo.log<br /> Alternatively, specify a unique context-param "webAppRootKey" per web application.<br /> For example, with "webAppRootKey = "demo.root":<br /> log4j.appender.myfile.File=${demo.root}/WEB-INF/demo.log <br /> -->
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webapp.root</param-value>
</context-param>
< !--<br /> Interval between config file refresh checks, in milliseconds. If not specified,<br /> no refresh checks will happen, which avoids starting Log4J's watchdog thread <br /> -->
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>3000</param-value>
</context-param>

... snip ...

<servlet>
<servlet-name>log4jConfigServlet</servlet-name>
<display-name>Spring Log4j Config Servlet</display-name>
<servlet-class>org.springframework.web.util.Log4jConfigServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>


I tried going to "The link provided by Cameron McKenzie for Websphere classloader [www.techincalfacilitation.com" but there was nothing on that web page about log4j that I could find.

Can anybody suggest anything to get log4j to work in RAD7? I'm at my wits end about this. Well, actually there is one last thing I am going to try. I'm going to change the web.xml to use a listener instead of a servlet. Below is the explanation of why, maybe, this could possibly help:


"... Bootstrap servlet for custom Log4J initialization in a web environment. Delegates to Log4jWebConfigurer (see its javadoc for configuration details). Note: This servlet should have a lower load-on-startup value in web.xml than ContextLoaderServlet, when using custom Log4J initialization. Note that this class has been deprecated for containers implementing Servlet API 2.4 or higher, in favor of Log4jConfigListener...."


So far I am: IBM 141 XML and Related Technologies Certified, Sun Cert Java Programmer, Sun Cert Java Developer, Sun Cert Java 2 Architect, Sun Cert J2EE Architect (part 1 only), Sun Cert J2EE Web Component Developer, Sun Cert Business Component Developer, and Microsoft Certified System Engineer for Win NT 4.
J Ridge
Greenhorn

Joined: Jun 29, 2007
Posts: 2
My suggestion (based on past experience with the same issue) is to simply use the Log4j API within your application. In other words, don't use the Common Logging APIs. This approach has been used to get log4j working on multiple project running on WebSphere v6.x. The alternative of trying to get common logging to work results in unreliable (if any) log4j output.

My opinion.
J Ridge
Greenhorn

Joined: Jun 29, 2007
Posts: 2
IBM has "finally" published documentation describing a couple of working approaches to making JCL and Log4j work. I haven't had a chance to try it, but the approaches suggested look good.

http://www-1.ibm.com/support/docview.wss?&uid=swg27010153

Enjoy
Scott Bown
Ranch Hand

Joined: Sep 06, 2007
Posts: 32
Cheers for that link to the IBM document.

Replaced the commons-loggin jars in websphere/lib, changed classloaded to parent_first and created the META-INF/services/org.apache commons.logging.LogFactory (and put org.apache.commons.logging.impl.LogFactoryImpl.Log4JLogger in that file)

Thanks,
Scott


Android + J2EE Developer
SCJP 5.0, SCWCD 1.4, SCDJWS 5
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Here's the classloading link!

Lets Get Loaded - Understanding WebSphere Classloaders and how J2EE Classes Get Into Memory

-Cameron McKenzie
Gareth Anderson
Greenhorn

Joined: Feb 27, 2006
Posts: 13
Hi everyone,

I've read all the documents and I still can't get log4j working using a commons-logging implementation.

With the
META-INF/services/org.apache commons.logging.LogFactory (and put org.apache.commons.logging.impl.LogFactoryImpl.Log4JLogger in that file)
trick, where does this particular META-INF file go into?

Also, I cannot change the class loader to PARENT_LAST as my entire application breaks, most of the documentation around this, even http://www-1.ibm.com/support/docview.wss?uid=swg27010153&aid=1 refers to changing the class loader.

Scott mentioned
Replaced the commons-loggin jars in websphere/lib
what exactly did you replace? The commons-logging-api jar file?
And why?

Currently we have a commons-logging-1.1.jar in the ear file, and a copy in the WEB-INF/lib directory of the war file.
There is a log4j.properties file in WEB-INF/classes.
I have tried putting commons-logging.properties files in many places but to no success, same with the META-INF/services/org.apache commons.logging.LogFactory trick.

How can I get this working on WebSphere 6?

Regards,
Gareth
Gareth Anderson
Greenhorn

Joined: Feb 27, 2006
Posts: 13
See
[URL=http://www-128.ibm.com/developerworks/forums/thread.jspa?messageID=14045904[/URL]
for further discussion of issue and solution.

I have found a solution for now...
[ February 11, 2008: Message edited by: Gareth Anderson ]
Nischit Shetty
Greenhorn

Joined: Feb 21, 2007
Posts: 25
For the solution, Refer the post by me at http://www.coderanch.com/t/451067/Websphere/Websphere-Apache-commons-logging-log#2678706
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Websphere 6.1 - Apache commons logging with log4j does not work
 
Similar Threads
Logging SQL statements
Tomcat 5.5.12 and log4J 1.3 Alpha7 -- how configure
INFO logging in Struts 1.3.10
log4j:WARN No appenders could be found for logger (log4jexample.LogExample).
Log4j creates an empty file