アペンダーのカスタマイズの例
このセクションでは、以前のバージョンの Log4j を使用するいくつかのアペンダーに使用されていたカスタマイズコードと、Log4j 2.0 との互換性を確保するためにこれらのアペンダーに推奨されるカスタマイズを示します。
Console アペンダー
Log4j 1.2 の使用法
Log4j 2.0 の使用法
wt.log4j.jmx.ConsoleAppender
# Define stdout appender, which sends log events to stdout
log4j.appender.stdout=wt.log4j.jmx.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p : %c %X{user} - %m%n
Console
# Define stdout appender, which sends log events to stdout
appender.stdout.type = Console
appender.stdout.name = stdout
appender.stdout.follow = false
appender.stdout.layout.type = PatternLayout
appender.stdout.layout.alwaysWriteExceptions = false
appender.stdout.layout.pattern = %-5p : %c %X{user} - %m%ex%n
RollingFile アペンダー
Log4j 1.2 の使用法
Log4j 2.0 の使用法
wt.log4j.jmx.DailyRollingFileAppender
# Define methodServerLogFile appender, which sends log events to a file
log4j.appender.methodServerLogFile=wt.log4j.jmx.DailyRollingFileAppender
log4j.appender.methodServerLogFile.File=${wt.logs.dir}/${wt.manager.serviceName}-${wt.jvm.startTime.formatted.short}-${wt.jvm.id}-log4j.log
log4j.appender.methodServerLogFile.DatePattern='.'yyyy-MM-dd
log4j.appender.methodServerLogFile.layout=org.apache.log4j.PatternLayout
log4j.appender.methodServerLogFile.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c %X{user} - %m%n
RollingFile
# Define methodServerLogFile appender, which sends log events to a file
appender.methodServerLogFile.type = RollingFile
appender.methodServerLogFile.name = methodServerLogFile
appender.methodServerLogFile.createOnDemand = true
appender.methodServerLogFile.fileName = ${sys:wt.logs.dir}/${sys:wt.manager.serviceName}-${sys:wt.jvm.startTime.formatted.short}-${sys:wt.jvm.id}-log4j.log
appender.methodServerLogFile.filePattern = ${sys:wt.logs.dir}/${sys:wt.manager.serviceName}-${sys:wt.jvm.startTime.formatted.short}-${sys:wt.jvm.id}-log4j.log.%d{yyyy-MM-dd}_%i
appender.methodServerLogFile.layout.type = PatternLayout
appender.methodServerLogFile.layout.alwaysWriteExceptions = false
appender.methodServerLogFile.layout.pattern = %d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t] %c %X{user} - %m%ex%n
appender.methodServerLogFile.policies.type = Policies
appender.methodServerLogFile.policies.time.type = TimeBasedTriggeringPolicy
appender.methodServerLogFile.policies.time.interval = 1
appender.methodServerLogFile.policies.time.modulate = true
appender.methodServerLogFile.policies.size.type = SizeBasedTriggeringPolicy
appender.methodServerLogFile.policies.size.size=9MB
appender.methodServerLogFile.strategy.type = DefaultRolloverStrategy
appender.methodServerLogFile.strategy.max = 2147483647
log4jMethodServer.properties での日付パターンについては、以下の例を参照してください。
appender.methodServerLogFile.layout.pattern = %d{​​​​​yyyy-MM-dd HH:mm:ss,SSS}​​​​​{​​​​​${​​​​​timeZone}​​​​​}​​​​​ %-5p [%t] %c %X{​​​​​user}​​​​​ - %m%ex%n
RollingFileAppender ロールオーバーポリシーについては、以下の例を参照してください。
appender.methodServerLogFile.filePattern = ${sys:wt.logs.dir}/${sys:wt.manager.serviceName}-${sys:wt.jvm.startTime.formatted.short}-${sys:wt.jvm.id}-log4j.log.%d{yyyy-MM-dd}_%i
appender.methodServerLogFile.policies.type = Policies
appender.methodServerLogFile.policies.midnight.type = SizeBasedMidnightTriggeringPolicy
appender.methodServerLogFile.policies.midnight.size=9MB
appender.methodServerLogFile.strategy.type = DefaultRolloverStrategy
appender.methodServerLogFile.strategy.max = 2147483647
${timeZone} パラメータは log4jMethodServer.properties での日付パターンにのみ使用します。RolingFile アペンダーにはファイルパターン %d{yyyy-MM-dd}_%i を使用する必要があります。
AsyncJDBCAppender アペンダー
Log4j 1.2 の使用法
Log4j 2.0 の使用法
wt.log4j.jmx.AsyncJDBCAppender
# Define MiscLogEvents appender, which sends log events (of sufficiently high severity) to the database
log4j.appender.MiscLogEvents=wt.log4j.jmx.AsyncJDBCAppender
log4j.appender.MiscLogEvents.BatchSize=200
log4j.appender.MiscLogEvents.IncludeMDC=true
log4j.appender.MiscLogEvents.threshold=WARN
# Throttle logging of exception traces to the database (adjust threshold as needed)
log4j.appender.MiscLogEvents.ThrowableElideThreshold=15
wt.log4j.jmx.AsyncJDBCAppender
# Define MiscLogEvents appender, which sends log events (of sufficiently high severity) to the database
appender.MiscLogEvents.name=MiscLogEvents
appender.MiscLogEvents.type=AsyncJDBCAppender
appender.MiscLogEvents.BatchSize=200
appender.MiscLogEvents.IncludeMDC=true
appender.MiscLogEvents.filter.threshold.type=ThresholdFilter
appender.MiscLogEvents.filter.threshold.level=WARN
# Throttle logging of exception traces to the database (adjust threshold as needed)
appender.MiscLogEvents.ThrowableElideThreshold=15
IncomingRmiStatsAppender アペンダー
Log4j 1.2 の使用法
Log4j 2.0 の使用法
wt.log4j.jmx.IncomingRmiStatsAppender
# Configure IncomingRmiStats appender
# Collects RMI statistics for viewing with wt.rmi.jmx.IncomingRmiStatsMonitor MBean; must instantiate this MBean (via MBean Loader) to access results
log4j.appender.IncomingRmiStats=wt.rmi.jmx.IncomingRmiStatsAppender
# Disable IncomingRmiStats appender by default; set threshold to INFO to enable
log4j.appender.IncomingRmiStats.threshold=WARN
wt.log4j.jmx.IncomingRmiStatsAppender

# Configure IncomingRmiStats appender
# Collects RMI statistics for viewing with wt.rmi.jmx.IncomingRmiStatsMonitor MBean; must instantiate this MBean (via MBean Loader) to access results
appender.IncomingRmiStats.name=IncomingRmiStats
appender.IncomingRmiStats.type=IncomingRmiStatsAppender
# Disable IncomingRmiStats appender by default; set threshold to INFO to enable
appender.IncomingRmiStats.filter.threshold.type=ThresholdFilter
appender.IncomingRmiStats.filter.threshold.level=WARN
これは役に立ちましたか?