# Activate the External folder appender.
# Be sure to configure/change the MY_EXTERNAL_FOLDER to have logs at the place you want.
log4j2.rootLogger.appenderRef.ExternalFolder.ref = ExternalFolder
# External folder appender
log4j2.appender.external.type = Routing
log4j2.appender.external.name = ExternalFolder
log4j2.appender.external.rewritePolicy.type = TalendKarafRewritePolicy
log4j2.appender.external.routes.type = Routes
log4j2.appender.external.routes.pattern = $\\{ctx:flowExecutionId\\}
log4j2.appender.external.routes.route1.type = Route
log4j2.appender.external.routes.route1.rolling.type = RollingFile
log4j2.appender.external.routes.route1.rolling.name = flowexecution-$\\{ctx:flowExecutionId\\}
log4j2.appender.external.routes.route1.rolling.fileName = MY_EXTERNAL_FOLDER/$\\{ctx:flowID\\}/$\\{ctx:flowExecutionId\\}.log
log4j2.appender.external.routes.route1.rolling.filePattern = MY_EXTERNAL_FOLDER/$\\{ctx:flowID\\}/$\\{ctx:flowExecutionId\\}.log.%i
# Use the 3 lines below for json pattern
log4j2.appender.external.routes.route1.rolling.layout.type = JsonTemplateLayout
log4j2.appender.external.routes.route1.rolling.layout.eventTemplateUri=${karaf.base.uri}/etc/jsonLogMinTemplate.json
log4j2.appender.external.routes.route1.rolling.layout.stackTraceElementTemplateUri=${karaf.base.uri}/etc/StackTraceElementLayout.json
# Uncomment two lines below for text pattern
#log4j2.appender.external.routes.route1.rolling.layout.type = PatternLayout
#log4j2.appender.external.routes.route1.rolling.layout.pattern = ${log4j2.pattern}
log4j2.appender.external.routes.route1.rolling.policy.type = SizeBasedTriggeringPolicy
log4j2.appender.external.routes.route1.rolling.policy.size = 100MB
log4j2.appender.external.routes.route1.rolling.strategy.type = DefaultRolloverStrategy
log4j2.appender.external.routes.route1.rolling.strategy.max = 1
# By having this set to ${ctx:flowExecutionId} it will match when flowExecutionId is not set in the context
log4j2.appender.external.routes.route2.type = Route
log4j2.appender.external.routes.route2.key = $\\{ctx:flowExecutionId\\}
log4j2.appender.external.routes.route2.null.type = CountingNoOp
log4j2.appender.external.routes.route2.null.name = CountingNoOp
このコードはあくまでも一例です。これをコピーして自分のシステムで使用する場合は、
MY_EXTERNAL_FOLDERをログの保存先となる実際のディレクトリー(Linuxでは
/home/usr/my-re-log、Windowsでは
D:/remote-engine/my-log-folder)に変更してください。
$\\{ctx:flowID\\}/$\\{ctx:flowExecutionId\\}の部分は、ログファイルの命名に使われる変数です。動的に生成されるログファイル名が必要ない場合は、プレーンテキストに置き換えてください。
これらの変更により、
log4j2.appender.external.route1.rolling.fileNameという行と
log4j2.appender.external.routes.route1.rolling.filePatternというの行が以下のように表示されます。
- Windowsの場合:
log4j2.appender.external.routes.route1.rolling.fileName = C:/my-personal-folder/my-log-foler/my-log.log
log4j2.appender.external.routes.route1.rolling.filePattern = C:/my-personal-folder/my-log-foler/my-log.log.%i
- Linux上で:
log4j2.appender.external.routes.route1.rolling.fileName = /home/usr/my-re-log/my-log.log
log4j2.appender.external.routes.route1.rolling.filePattern = /home/usr/my-re-log/my-log.log.%i