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

Piotr Karwasz commented on LOG4J2-3437:
---------------------------------------

[~PoojaTheCoder], I fixed the NPE editing the comment above.

Regarding the complexity problems in your setup, the advise you got on the 
{{log4j-user}} mailing list has been unanimous from day one: implement your 
complex logic in native Log4j 2.x and use the bridge for the 
{{org.apache.log4j.Logger}} -> {{org.apache.logging.log4j.Logger}} message 
relay only.

Using Log4j 2.x directly to inject (native Log4j 2.x) {{{}FileAppender{}}}s 
into the configuration will save you a lot of coding. What you are looking for 
already exists in Log4j 2.x: it is called 
[DynamicThresholdFilter|https://logging.apache.org/log4j/2.x/manual/filters.html#DynamicThresholdFilter].
 You can add it to the logger config above using the 
{{LoggerConfig.Builder#withFilter}} method. IIRC you want {{onMatch=ACCEPT}} 
and {{{}onMismatch=NEUTRAL{}}}.

It works by looking up a key in the [thread 
context|https://logging.apache.org/log4j/2.x/manual/thread-context.html] (a 
sort of {{{}ThreadLocal{}}}). If the key is absent, the configured logger 
config level is used. If the key is present and the message is less specific 
than the level associated to the key, the message is passed to the appender. 
Otherwise the configured logger config level is checked.

> Log4j 1.x bridge Request to support programmatically configuring Log4j.
> -----------------------------------------------------------------------
>
>                 Key: LOG4J2-3437
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3437
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Log4j 1.2 bridge
>    Affects Versions: 2.17.2
>            Reporter: Pooja Pandey
>            Priority: Major
>
> As per log4j migration documentation 
> ([https://logging.apache.org/log4j/2.x/manual/migration.html),|https://logging.apache.org/log4j/2.x/manual/migration.html)]
>  I understand that currently log4j 1.x bridge 2.17.2 doesn't support 
> programmatically configuring log4j appenders.
> *#### Limitations of the Log4j 1.x bridge*
>  # *They must not programmatically configure Log4j.*
>  
> In our application, we have a requirement where we need to add many 
> FileAppender programmatically with various log threshold values.
>  
> Hoping to get this feature supported in future versions for log4j1.x bridge.
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to