0

アプリケーションでエラーをログに記録するために、Apache の log4j を使用しています。Tomcat サーバーを起動すると、ログ情報情報が期待どおりにログ ファイルに書き込まれます (Tomcat サーバーを停止すると、ログ情報もログ ファイルに書き込まれます)。しかし、アプリケーションの使用を開始すると、アプリを介して書き込まれると予想される情報がログ ファイルに書き込まれません。たとえば、例外を発生させる入力を与えていますが、log.error(e,e) がログ ファイルに書き込まれません。

これが私がLoggerを使用している方法です
static Logger log = Logger.getLogger(MyClass.class);


log.info("my message" );
log.error(e,e);

助けてください

編集: log4j.properties ファイルの内容を追加する

log4j.rootLogger =INFO, FILE, stdout log4j.appender.FILE=org.apache.log4j.RollingFileAppender log4j.appender.FILE.File=${catalina.home}/logs/myapp.log log4j.appender.FILE.layout=org.apache.log4j.PatternLayout log4j.appender.FILE.layout.ConversionPattern=%d{ABSOLUTE} %5p\t\t%c{1} :%L - %m%n

4

1 に答える 1

0

It seems that you have not configured your logger. Please find log4j.xml or logging.properties typically located under TOMCAT_HOME/conf. Edit them to include your application's package.

This will help you to write your application level log messages to log file of your server (tomcat).

Better way is to manage your own logging configuration and files. Create log4j.xml file and put it under WEB-INF/classes into your application. You can find a lot of examples and tutorials that will help you to write your log4j.xml. For example this one: http://logging.apache.org/log4j/1.2/manual.html

于 2012-07-31T18:33:21.843 に答える