私はロンボクのlog4j2ロガーを使用しており、ThreadContextマップに基づいてルーティングアペンダーを設定する必要があります。ルートキーはスクリプトで決定されます。ここでは全体log4j2.xml設定ファイルされる:Log4j2ルーティングアペンダーJavaScript設定エラー
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%highlight{%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %c{1}: %msg%n%throwable}"/>
</Console>
<RollingFile name="GeneralRollingFile" filename="log/test-log.log"
filepattern="log/test-log-%d{yyyy-MM-dd HH:mm:ss}.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %c{1}: %msg%n%throwable"/>
<Policies>
<SizeBasedTriggeringPolicy size="25 MB"/>
</Policies>
<DefaultRolloverStrategy max="20"/>
</RollingFile>
<Routing name="Routing">
<Routes>
<Script name="RoutingInit" language="JavaScript">
<![CDATA[
if (logEvent.getContextMap().containsKey("operation-1")) {
return "operation-1";
} else if (logEvent.getContextMap().containsKey("operation-2")) {
return "operation-2";
} else {
return "general";
}
]]>
</Script>
<Route key="general" ref="GeneralRollingFile"/>
<Route key="operation-1">
<RollingFile name="operation-1-rolling"
fileName="log/operation-1/${ctx:operation-1}.log"
filePattern="log/operation-1/${ctx:operation-1}-%d{yyyy-MM-dd HH:mm:ss}.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %c{1}: %msg%n%throwable"/>
<Policies>
<SizeBasedTriggeringPolicy size="25 MB"/>
</Policies>
<DefaultRolloverStrategy max="20"/>
</RollingFile>
</Route>
<Route key="operation-2">
<RollingFile name="operation-2-rolling"
fileName="log/operation-2/${ctx:operation-2}.log"
filePattern="log/operation-2/${ctx:operation-2}-%d{yyyy-MM-dd HH:mm:ss}.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %c{1}: %msg%n%throwable"/>
<Policies>
<SizeBasedTriggeringPolicy size="25 MB"/>
</Policies>
<DefaultRolloverStrategy max="20"/>
</RollingFile>
</Route>
</Routes>
</Routing>
</Appenders>
<Loggers>
<Root level="trace" additivity="false">
<AppenderRef ref="Console"/>
<AppenderRef ref="Routing"/>
</Root>
</Loggers>
しかし、私は次のエラーを取得しています:
main ERROR Error running script RoutingInit javax.script.ScriptException: <eval>:2:24 Invalid return statement
return "operation-1";
Log4j2のドキュメントは私たちに似たスクリプトの例を示します、それは私のエーテルのために働かない。 私はJSにかなり新しいですが、このコードは有効なスクリプトのようです。何か間違っていますか?
ありがとうございます。
ありがとう。ソリューションのアプローチは似ていました。単にリターンを取り除くだけです。 – void