Using log4j in oc4j 10.1.3

爷,独闯天下 提交于 2019-12-23 03:20:35

问题


I have a web application running on OC4J 10.1.3. I am trying to do some logging using log4j. The messages show up in my IDE console as expected, but nothing is going into the application.log in OC4J. Anybody know what I need to do to get this working?

Here's my log4j.properties:

log4j.rootCategory=DEBUG, CON1

# CON1 is set to be ConsoleAppender sending its output to System.out
log4j.appender.CON1=org.apache.log4j.ConsoleAppender
log4j.appender.CON1.layout=org.apache.log4j.PatternLayout
log4j.appender.CON1.layout.ConversionPattern=%p: [%l] - %m%n

log4j.logger.org.apache.ojb.broker.accesslayer=DEBUG

And in my java classes I'm doing this:

Logger logger = Logger.getLogger(getClass().getName());
logger.debug("Test message.");

回答1:


Configure OC4J to log the console output to a file.
If you are using the full IAS add this to the opmn.xml

<data id="oc4j-options" value="-verbosity 10 -err err.log -out out.log"/>

If you are using the stanalone OC4j:

  java -jar oc4j.jar -err err.log -out out.log



回答2:


The OC4J Developer's Guide states how log4j is to be used in OC4J.

Specifically, log4.properties should be placed in WEB-INF/classes where it can be located by the the log4j runtime jar (usually placed in WEB-INF/lib). Placing the log4j artifacts in the applib directory is bad practice and should be avoided.

I'm unsure of this, but if log4j is not writing to application.log, then you must check the contents of the ODL log (some details of ODL configuration are available in the Developer's Guide), and if OC4J is managed by OPMN it is also a good idea to check the managed process console log in the opmn/logs directory.




回答3:


I know this is an old question, but I did some additional research into this earlier today.

It turns out that OC4J includes an OracleAppender for Log4j. This is the sample configuration for it that would go in log4j.properties:

log4j.appender.OJDL=oracle.core.ojdl.log4j.OracleAppender
log4j.appender.OJDL.LogDirectory=${oracle.j2ee.home}/log/oc4j
#log4j.appender.APP1.MaxSize=1000000
#log4j.appender.APP1.MaxSegmentSize=200000
#log4j.appender.APP1.Encoding=iso-8859-1
log4j.appender.OJDL.ComponentId=OracleProd

This configuration directs log4j messages into the ORACLE_HOME/j2ee/home/log/oc4j/log.xml file, which LogViewer reads and then displays in Application Server Control as Diagnostics Logs.

This can then be added as a logger at some level. For example, to add it to the root logger in addition to logging to the console:

log4j.rootLogger=DEBUG, CON1, OJDL

Note: I'm not sure what the difference is between rootLogger and rootCategory.

Note 2: This shows up in the Diagnostics log rather than the application log.



来源:https://stackoverflow.com/questions/1341569/using-log4j-in-oc4j-10-1-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!