日期:2014-05-16  浏览次数:21192 次

apache log4j API自身log输出设置
最近遇到一个问题,ERA应用部署在weblogic上,在project/WEB-INF/classes下的log4j.propties总是出现有时候可以正常加载,有时候却不能正常加载。

在不能正常加载的时候,报告如下警告信息:

log4j:WARN No appenders could be found for logger (com.jl.yyi.web.filter.F00yyi001Filter).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.


经过查看log4j的源码发现,其实log4j自己的API里的日志是通过System.out.print的方式输出到标准输出的,具体参考org.apache.log4j.helpers.LogLog这个类。

那么如何将log4j自己的log输出来呢,通过读LogLog这个类的源码知道这需要在系统属性里配置log4j.debug=true这个参数,因此,在D:\Oracle\Middleware\user_projects\domains\log4j_test_domain\bin\setDomainEnv.cmd这个脚本里修改

set JAVA_PROPERTIES=%JAVA_PROPERTIES% %EXTRA_JAVA_PROPERTIES% 


为:

set JAVA_PROPERTIES=%JAVA_PROPERTIES% %EXTRA_JAVA_PROPERTIES% -Dlog4j.debug=true


重新启动weblogic,访问作业画面,得到如下详细信息:

log4j: Trying to find [log4j.xml] using context classloader weblogic.utils.classloaders.ChangeAwareClassLoader@21aa5a31 finder: weblogic.utils.classloaders.CodeGenClassFinder@2b5229f4 annotation: jlerp_f@f.
log4j: Trying to find [log4j.xml] using weblogic.utils.classloaders.ChangeAwareClassLoader@21aa5a31 finder: weblogic.utils.classloaders.CodeGenClassFinder@2b5229f4 annotation: jlerp_f@f class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader weblogic.utils.classloaders.ChangeAwareClassLoader@21aa5a31 finder: weblogic.utils.classloaders.CodeGenClassFinder@2b5229f4 annotation: jlerp_f@f.
log4j: Using URL [zip:/usr/oracle/Middleware/user_projects/domains/erp_domain/servers/F321/tmp/_WL_user/jlerp_f/e0br6s/war/WEB-INF/lib/_wl_cls_gen.jar!/log4j.properties] for automatic log4j configuration.
log4j: Reading configuration from URL zip:/usr/oracle/Middleware/user_projects/domains/erp_domain/servers/F321/tmp/_WL_user/jlerp_f/e0br6s/war/WEB-INF/lib/_wl_cls_gen.jar!/log4j.properties
log4j: Parsing for [root] with value=[DEBUG, f_logout,f_mail_logout,developement_logout].
log4j: Level token is [DEBUG].
log4j: Category root set to DEBUG
log4j: Parsing appender named "f_logout".
log4j: Parsing layout options for "f_logout".
log4j: Setting property [conversionPattern] to [%X{mgdSvrName} | %X{userCode} | %d{yyyy-MM-dd HH:mm:ss} | %l | %p | %m%n].
log4j: End of parsing for "f_logout".
log4j: Setting property [encoding] to [UTF-8].
log4j: Setting property [file] to [/var/ftp/logs/[F321]/f/f.log].
log4j: Setting property [maxBackupIndex] to [50].
log4j: Setting property [append] to [true].
log4j: Setting property [maxFileSize] to [5120KB].
log4j: setFile called: /var/ftp/logs/[F321]/f/f.log, true
log4j: setFile ended
log4j: Parsed "f_logout" options.
log4j: Parsing appender named "f_mail_logout".
log4j: Parsing layout options for "f_mail_logout".
log4j: Setting property [conversionPattern] to [%X{mgdSvrName} | %X{userCode} | %d{yyyy-MM-dd HH:mm:ss} | %l | %p | %m%n].
log4j: End of parsing for "f_mail_logout".
log4j: Setting property [SMTPHost] to [mail.ejianlong.com].
log4j: Setting property [from] to [jlerp@ejianlong.com].
log4j: Setting property [SMTPPassword] to [11111sss].
log4j: Setting property [threshold] to [ERROR].
log4j: Setting property [subject] to [Test1 JLerp ErrorMessage[f]].
log4j: Setting property [to] to [wushaofeng@ejianlong.com].
log4j: Setting property [SMTPUsername] to [jlerp].
log4j: Setting property [bufferSize] to [512].
log4j: Parsed "f_mail_logout" options.
log4j: Parsing appender named "developement_logout".
log4j: Parsing layout options for "developement_logout".
log4j: Setting property [conversionPattern] to [[%p] [%l] %10.10c - %m%n].
log4j: End of parsing for "developement_logout".
log4j: Parsed "developement_logout" options.
log4j: Parsing for [com.jl.ft] with value=[DEBUG,