[ 
https://issues.apache.org/jira/browse/LOG4J2-1023?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14552152#comment-14552152
 ] 

Remko Popma commented on LOG4J2-1023:
-------------------------------------

This is possible, but you'll need to specify
* which log events to rewrite and which to leave alone 
* what the desired level is

Here is an example:
{code}
@Plugin(name = "LevelRewritePolicy", category = "Core",
        elementType = "rewritePolicy", printObject = true)
public final class LevelRewritePolicy implements RewritePolicy {

    @Override
    public LogEvent rewrite(final LogEvent event) {
        
        if (!event.getLoggerFqcn().startsWith("com.welogalot")) 
            return event;

        // always log at trace level
        LogEvent result = new Log4jLogEvent(event.getLoggerName(), 
event.getMarker(),
            event.getLoggerFqcn(), Level.TRACE, event.getMessage(),
            event.getThrown(), event.getContextMap(), event.getContextStack(),
            event.getThreadName(), event.getSource(), event.getTimeMillis());

        return result;
    }
}
{code}





> New RewritePolicy for changing level of a log event
> ---------------------------------------------------
>
>                 Key: LOG4J2-1023
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1023
>             Project: Log4j 2
>          Issue Type: New Feature
>          Components: Core
>    Affects Versions: 2.3
>            Reporter: Mikael Ståldal
>              Labels: configuration
>
> It would be useful to have a RewritePolicy for changing the level of a log 
> event.
> Some 3rd party libraries log stuff on wrong level, and I would like to be 
> able to translate it.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to