How do you use Log4j to write/capture stdout and stderr to a file and using Windows and Tomcat 5.5 (Java)?

China☆狼群 提交于 2019-12-04 03:20:06

1) How do I compile any of these classes? What should be the classpath? I tried compiling the class from the sysgears link but it returned 7 errors such as unable to find symbol Class Logger and symbol Class OutputStream.

You need to have the log4j jar on your classpath, and import the correct classes at the top of your file. Something like,

import java.io.PrintStream;
import java.io.OutputStream;
import org.apache.log4j.Logger;

you can achieve this with an appender:

log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold = DEBUG
log4j.appender.stdout.Target   = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %d{ISO8601} %-5p [%F:%L] : %m%n

Then use this appender with your logger, for example:

log4j.rootLogger = DEBUG, stdout

Of course you can use the Target above different, maybe with System.err

Hope it helps.

Cheers, Christian

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