• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Websphere 6.1 - Apache commons logging with log4j does not work

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put it in the lib folder of the WEB-INF or any folder which is in the classpath.

Regards
Yogesh
 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...."
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the classloading link!

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

-Cameron McKenzie
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the solution, Refer the post by me at https://coderanch.com/t/451067/Websphere/Websphere-Apache-commons-logging-log#2678706
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic