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

Andre Bogus commented on LOG4J2-468:
------------------------------------

What would the runtime semantics for "adding a new Logger" be?

* Getting a Logger object from the LogManager - You can already do that, just 
call LogManager.getLogger(). No new feature here.
* Setting the log level for a logger at runtime: You may want to look into the 
JMX extensions, which I haven't tested yet, but the docs promise to allow 
things like setting log levels.
* Adding ore redirecting an appender. This will need a property in your 
configuration, along with a routing appender and calling reconfigure. For 
example:

{noformat}<?xml version="1.0" encoding="UTF-8" ?>
<configuration status="warn">
        <properties>
                <property name="filename">$${sys:LOG_FILENAME}</property>
        </properties>
        <appenders>
            <Routing name="routing">
                <Routes pattern="$${ctx:zwangsgruppe}">
                        <Route>
                                <File name="file" fileName="${filename}">
                                        <PatternLayout pattern="..."/>
                                </File>
                        </Route>
                </Routes>
            </Routing>
        </appenders>
       ...
</configuration>
{noformat}

(Yeah, it's ugly) Then in the code, you can do:

System.setProperty("LOG_FILENAME", logFilename);
((org.apache.logging.log4j.core.LoggerContext)LogManager.getContext()).reconfigure();

Not very nice either, but it should work.

> Dynamically (programmatically) add logger in Log4j2
> ---------------------------------------------------
>
>                 Key: LOG4J2-468
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-468
>             Project: Log4j 2
>          Issue Type: New Feature
>            Reporter: Dean Anderson
>
> Please add the ability for someone to dynamically add a new Logger 
> programmatically.
> Thank you.



--
This message was sent by Atlassian JIRA
(v6.1.4#6159)

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

Reply via email to