はじめに
以下で作成したWebサービスで、デフォルトはコンソールログのみだけだが、 ログファイルとして出力する方法を纏める。 * Axis2http://blogs.yahoo.co.jp/dk521123/36056462.html
* Metrohttp://blogs.yahoo.co.jp/dk521123/36139336.html
手順
[1] 【Tomcat のホーム】\webapps\【自作したサービス】\WEB-INF\classes (例「C:\tomcat7\webapps\axis2\WEB-INF\classes」)配下にある 「log4j.properties」を以下の「log4j.properties 修正例」を参考に修正する [2] Tomcat を再起動する
log4j.properties 修正例
修正前
# Set root category priority to INFO and its only appender to CONSOLE. log4j.rootCategory=INFO, CONSOLE #log4j.rootCategory=INFO, CONSOLE, LOGFILE # Set the enterprise logger priority to FATAL log4j.logger.org.apache.axis2.enterprise=FATAL log4j.logger.de.hunsicker.jalopy.io=FATAL log4j.logger.httpclient.wire.header=FATAL log4j.logger.org.apache.commons.httpclient=FATAL # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=[%p] %m%n # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender log4j.appender.LOGFILE.File=axis2.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
修正後
# Set root category priority to INFO and its only appender to CONSOLE. #log4j.rootCategory=INFO, CONSOLE log4j.rootCategory=DEBUG, CONSOLE, LOGFILE # Set the enterprise logger priority to FATAL log4j.logger.org.apache.axis2.enterprise=FATAL log4j.logger.de.hunsicker.jalopy.io=FATAL log4j.logger.httpclient.wire.header=DEBUG log4j.logger.httpclient.wire.content=DEBUG log4j.logger.org.apache.commons.httpclient=DEBUG # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=[%p] %m%n # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender log4j.appender.LOGFILE.File=./logs/axis2.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.MaxFileSize=50000KB log4j.appender.LOGFILE.MaxBackupIndex=10 log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
参考文献
http://axis.apache.org/axis/ja/wiki-java/Logging.htmlhttp://osdir.com/ml/axis-user-ws.apache.org/2010-01/msg00199.html