为了将 hybris 日志与控制台(catalina)包装器(tanuki)和 tomcat 分开,我创建了这两个配置。
#local.properties
log4j.appender.FILE = org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.File = ${HYBRIS_LOG_DIR}/tomcat/hybris.log
log4j.appender.FILE.Append = true
log4j.appender.FILE.DatePattern = '-'yyyy-MM-dd
log4j.appender.FILE.layout = org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern = %d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%-5p|%X{RemoteAddr}|%X{TomcatSessionId}|%c] %m%n
log4j.rootLogger=INFO, FILE
这被放入 local.properties 并在 hybris.log 中创建日志我还创建了这个:
#log4j_init_tomcat.properties
log4j.appender.TOMCAT_FILE = org.apache.log4j.DailyRollingFileAppender
log4j.appender.TOMCAT_FILE.File = ${HYBRIS_LOG_DIR}/tomcat/tomcat.log
log4j.appender.TOMCAT_FILE.Append = true
log4j.appender.TOMCAT_FILE.DatePattern = '-'yyyy-MM-dd
log4j.appender.TOMCAT_FILE.layout = org.apache.log4j.PatternLayout
log4j.appender.TOMCAT_FILE.layout.ConversionPattern = %d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%-5p|%X{RemoteAddr}|%X{TomcatSessionId}|%c] %m%n
log4j.rootLogger=INFO, TOMCAT_FILE
它放置在 log4j_init_tomcat.properties 中,它作为 tanuki 包装器加载为
wrapper.java.additional.22=-Dlog4j.configuration=file:%CATALINA_BASE%/conf/log4j_init_tomcat.properties
Tomcat.log 文件已创建但为空,我看不出任何原因。
这是控制台日志文件的输出:
INFO | jvm 1 | main | 2015/09/16 22:36:32.711 | log4j: Reading configuration from URL file:../conf/log4j_init_tomcat.properties
INFO | jvm 1 | main | 2015/09/16 22:36:32.711 | log4j: Parsing for [root] with value=[INFO, TOMCAT_FILE].
INFO | jvm 1 | main | 2015/09/16 22:36:32.711 | log4j: Level token is [INFO].
INFO | jvm 1 | main | 2015/09/16 22:36:32.711 | log4j: Category root set to INFO
INFO | jvm 1 | main | 2015/09/16 22:36:32.711 | log4j: Parsing appender named "TOMCAT_FILE".
INFO | jvm 1 | main | 2015/09/16 22:36:32.711 | log4j: Parsing layout options for "TOMCAT_FILE".
INFO | jvm 1 | main | 2015/09/16 22:36:32.711 | log4j: Setting property [conversionPattern] to [%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%-5p|%X{RemoteAddr}|%X{TomcatSessionId}|%c] %m%n].
INFO | jvm 1 | main | 2015/09/16 22:36:32.711 | log4j: End of parsing for "TOMCAT_FILE".
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Setting property [datePattern] to ['-'yyyy-MM-dd].
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Setting property [append] to [true].
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Setting property [file] to [/opt/hybris/log/tomcat/tomcat.log].
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: setFile called: /opt/hybris/log/tomcat/tomcat.log, true
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: setFile ended
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Appender [TOMCAT_FILE] to be rolled at midnight.
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Parsed "TOMCAT_FILE" options.
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Finished configuring.
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Parsing for [root] with value=[INFO, FILE].
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Level token is [INFO].
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Category root set to INFO
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Parsing appender named "FILE".
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Parsing layout options for "FILE".
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Setting property [conversionPattern] to [%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%-5p|%X{RemoteAddr}|%X{TomcatSessionId}|%c] %m%n].
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: End of parsing for "FILE".
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Setting property [append] to [true].
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Setting property [file] to [/opt/hybris/log/tomcat/hybris.log].
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Setting property [datePattern] to ['-'yyyy-MM-dd].
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: setFile called: /opt/hybris/log/tomcat/hybris.log, true
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: setFile ended
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Appender [FILE] to be rolled at midnight.
INFO | jvm 1 | main | 2015/09/16 22:36:32.812 | log4j: Parsed "FILE" options.
INFO | jvm 1 | main | 2015/09/16 22:36:32.912 | log4j: Parsing for [org.apache.cxf] with value=[WARN].
INFO | jvm 1 | main | 2015/09/16 22:36:32.912 | log4j: Level token is [WARN].
INFO | jvm 1 | main | 2015/09/16 22:36:32.912 | log4j: Category org.apache.cxf set to WARN
INFO | jvm 1 | main | 2015/09/16 22:36:32.912 | log4j: Handling log4j.additivity.org.apache.cxf=[null]
INFO | jvm 1 | main | 2015/09/16 22:36:32.912 | log4j: Parsing for [de.hybris.platform.print.comet.utils.StopWatch] with value=[ALL].
INFO | jvm 1 | main | 2015/09/16 22:36:32.912 | log4j: Level token is [ALL].
INFO | jvm 1 | main | 2015/09/16 22:36:32.912 | log4j: Category de.hybris.platform.print.comet.utils.StopWatch set to ALL
INFO | jvm 1 | main | 2015/09/16 22:36:32.913 | log4j: Handling log4j.additivity.de.hybris.platform.print.comet.utils.StopWatch=[null]
INFO | jvm 1 | main | 2015/09/16 22:36:32.913 | log4j: Parsing for [print.soap.logging] with value=[ALL].
INFO | jvm 1 | main | 2015/09/16 22:36:32.913 | log4j: Level token is [ALL].
INFO | jvm 1 | main | 2015/09/16 22:36:32.913 | log4j: Category print.soap.logging set to ALL
INFO | jvm 1 | main | 2015/09/16 22:36:32.913 | log4j: Handling log4j.additivity.print.soap.logging=[null]
INFO | jvm 1 | main | 2015/09/16 22:36:32.913 | log4j: Parsing for [your.package] with value=[debug].
INFO | jvm 1 | main | 2015/09/16 22:36:32.913 | log4j: Level token is [debug].
INFO | jvm 1 | main | 2015/09/16 22:36:32.913 | log4j: Category your.package set to DEBUG
INFO | jvm 1 | main | 2015/09/16 22:36:32.913 | log4j: Handling log4j.additivity.your.package=[null]
我正在为 logstash 做所有这些,以便可以正确记录它。我希望有一个人可以帮助我!
诚挚的问候, Fide