# 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
Dieser Code fungiert lediglich als Beispiel. Wenn Sie ihn in Ihr System kopieren, vergessen Sie nicht,
MY_EXTERNAL_FOLDER zu dem Verzeichnis umzuändern, in dem Sie die Logs speichern möchten, z. B.
/home/usr/my-re-log in Linux oder
D:/remote-engine/my-log-folder in Windows.
Der Teil $\\{ctx:flowID\\}/$\\{ctx:flowExecutionId\\} entspricht den für die Benennung der Logdateien zu verwendenden Variablen. Wenn Sie keinen dynamisch generierten Logdatei-Namen benötigen, ersetzen Sie ihn durch Klartext.
Nach diesen Änderungen sehen die Zeilen
log4j2.appender.external.routes.route1.rolling.fileName und
log4j2.appender.external.routes.route1.rolling.filePattern folgendermaßen aus:
- In 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
- In 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