Websphere 6.1 - Apache commons logging with log...

Cause of Problem: 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 Websphere 6.1. When the application runs in the application server, it uses the default 'org.apache.commons.logging.impl.Jdk14Logger'  other than

'org.apache.commons.logging.impl.Log4jLogger'.

 

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

Solution:

Because websphere uses the default 'org.apache.commons.logging.impl.Jdk14Logger', therefore we need to make the websphere to load the configured log4j of our project other than load its’ default configure, we only need to add the following configure file to the foler “META-INF/services” of  the ear package.

File Name : org.apache.commons.logging.LogFactory :

Just make the contents of that file as the following:

org.apache.commons.logging.impl.Log4jFactory

The META-INF/services approach has been working for us (who give the help in the forum) for years on many different versions of WAS. (We're on 6.1 now) You don't need (or likely want) to change the classloader ordering policy like the following.

commons-logging.properties:

priority=1

org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl

 

A couple references:

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

转载于:https://my.oschina.net/uniquejava/blog/109867

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值