[
https://issues.apache.org/jira/browse/LOG4J2-541?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13933115#comment-13933115
]
James Pretorius commented on LOG4J2-541:
----------------------------------------
Hi Ralph,
Forgive me but I haven't actually looked at this in great detail as no doubt it
would take me some time to wrap my head around the intricacies of the project
but in the context of the DynamicThresholdFilter is it not just a case of
pulling the value from StrSubstitutor, using the key, much like you would find
the route with a routing appender pattern?
Sample code for DynamicThresholdFilter.java below.
{code:title=DynamicThresholdFilter.java |borderStyle=solid}
@Override
public Result filter(final LogEvent event) {
String value = config.getStrSubstitutor().replace(event, key);
return filter(value, event.getLevel());
}
private Result filter(String value, final Level level) {
if (value != null) {
Level ctxLevel = levelMap.get(value);
if (ctxLevel == null) {
ctxLevel = defaultThreshold;
}
return level.isAtLeastAsSpecificAs(ctxLevel) ? onMatch : onMismatch;
}
return Result.NEUTRAL;
}
{code}
The ThresholdFilter would need to be created with a levelPattern and not a
level. levelPattern could be a level or a pattern, then the same rules would
apply:
{code:title=ThresholdFilter.java |borderStyle=solid}
@Override
public Result filter(final LogEvent event) {
Level thresholdLevel = Level.getLevel(levelPattern);
if (thresholdLevel == null) {
String levelName = config.getStrSubstitutor().replace(event,
levelPattern);
thresholdLevel = Level.toLevel(levelName, Level.ERROR);
}
return filter(thresholdLevel, event.getLevel());
}
private Result filter(Level thresholdLevel, final Level level) {
return level.isAtLeastAsSpecificAs(thresholdLevel) ? onMatch :
onMismatch;
}
{code}
> Allow all lookup types in DynamicThresholdFilter
> ------------------------------------------------
>
> Key: LOG4J2-541
> URL: https://issues.apache.org/jira/browse/LOG4J2-541
> Project: Log4j 2
> Issue Type: Improvement
> Components: Filters
> Affects Versions: 2.0-rc1
> Environment: Windows 7
> Java 6
> Reporter: James Pretorius
> Labels: features
>
> Currently the DynamicThresholdFilter only supports key values pairs in the
> ThreadContextMap. It would be good to see this expanded to include all log4j2
> lookups.
> In the below example the threshold level would be stored in a map value
> substituted at runtime.
> {code:javascript|title=log4j2.json snippet}
> "root":{
> "AppenderRef":{
> "ref":"Console Appender",
> "DynamicThresholdFilter":{
> "defaultThreshold":"debug",
> "key":"$${map:log.console.level}",
> "onMatch":"ACCEPT",
> "onMisMatch":"DENY",
> "keyValuePair":[
> {
> "key":"off",
> "value":"off"
> },
> {
> "key":"fatal",
> "value":"fatal"
> },
> {
> "key":"error",
> "value":"error"
> },
> {
> "key":"warn",
> "value":"warn"
> },
> {
> "key":"info",
> "value":"info"
> },
> {
> "key":"debug",
> "value":"debug"
> },
> {
> "key":"trace",
> "value":"trace"
> }
> ]
> }
> }
> }
> {code}
> Alternatively, allow the threshold filter to be substituted with a runtime
> lookup value.
> {code:javascript|title=log4j2.json snippet}
> "root":{
> "AppenderRef":{
> "ref":"Console Appender",
> "ThresholdFilter":{
> "level":"$${map:log.console.level}",
> "onMatch":"ACCEPT",
> "onMisMatch":"DENY"
> }
> }
> }
> {code}
> The above will allow the developer to customise the log level at runtime
> across various loggers, appenders etc.
--
This message was sent by Atlassian JIRA
(v6.2#6252)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]