I'm using log4j2 in oracle adf 12c application.
One of the requirements of our customer is to have different log levels for different logged-in users and also to change the log levels dynamically for a user.Also the Administrator should have a control to stop all the logging.
i.e Lets say 'User A' needs Trace log level and 'User B' needs Error log level. If both the users are logged in simultaneously, the application should log in Trace level for 'User A' and in Error level for 'User B'. And if the 'User B' wants to log in FATAL level he should be able to change the configuration dynamically.
Following is the log4j2 config file.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace">
<MapFilter onMatch="ACCEPT" operator="or">
<KeyValuePair key="$${ctx:LOGLEVELYN}" value="Y"/>
</MapFilter>
<Appenders>
<File name="file" fileName="./adfAppCustomLogs/TestLog4j2.log">
<PatternLayout>
<Pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} %-5level %class %L %M - %msg%xEx%n</Pattern>
</PatternLayout>
</File>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%m%n"/>
</Console>
<Routing name="AppRouting">
<Routes pattern="$${ctx:LOGGEDSESSIONID}">
<!-- This route is chosen if ThreadContext has no value for key ROUTINGKEY. -->
<Route key="$${ctx:LOGGEDSESSIONID}">
<RollingFile name="Rolling-ALL" fileName="./adfAppCustomLogs/DefaultAll.log"
filePattern="./adfAppCustomLogs/archive/${date:yyyy-MM}/DefaultAll-%d{MM-dd-yyyy}-%i.txt.gz">
<PatternLayout>
<Pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} %-5level %t %msg%xEx%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
</RollingFile>
</Route>
<!-- This route is chosen if ThreadContext has value 'user' for key ROUTINGKEY. -->
<Route>
<RollingFile name="Rolling-OTHER-${ctx:LOGGEDSESSIONID}"
fileName="./adfAppCustomLogs/${ctx:LOGINID}-${ctx:LOGGEDSESSIONID}.log"
filePattern="./adfAppCustomLogs/archive/${date:yyyy-MM}/${ctx:LOGINID}-%d{MM-dd-yyyy}-%i.txt.gz">
<PatternLayout>
<Pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} %-5level %t %msg%xEx%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
<!-- <DefaultRolloverStrategy max="100"/> -->
</RollingFile>
</Route>
</Routes>
</Routing>
<Async name="async" bufferSize="1000" includeLocation="true">
<AppenderRef ref="AppRouting"/>
</Async>
</Appenders>
<Loggers>
<Root level="trace">
<!--<AppenderRef ref="file" level="DEBUG"/> -->
<AppenderRef ref="async"/>
<!-- Uncomment the following if you want the log to be printed in weblogic console -->
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>
I'm trying to create multiple loggers with a different loglevel for each one but nothing worked.
It would be great if you can give me some pointers or hints.
コメント