[
https://issues.apache.org/jira/browse/LOG4J2-2381?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
nanshakov updated LOG4J2-2381:
------------------------------
Description:
I wanna add other configuration for loggers. For example, we have:
log4j2.xml
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration shutdownHook="disable"
monitorInterval="30">
<Appenders>
<File name="MyFile" fileName="all.log" immediateFlush="true" append="false">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level
%logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="ALL" additivity="false">
<AppenderRef ref="MyFile" />
</Root>
</Loggers>
</Configuration>
{code}
And we have the folder where we can add some XML, for example:
Console.xml
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration shutdownHook="disable">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="[%highlight{%-5level}] %d{DEFAULT} %c{1}.%M() -
%msg%n%throwable{short.lineNumber}" />
</Console>
</Appenders>
<Loggers>
<Root level="ALL" additivity="false">
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>{code}
I wanna understanding how apply this config to loggers. I have WatchService
and the code, which doesn't work:
{code:java}
private void AddConfiguration(String fileName) {
logger.info("Adding log4j configuration settings");
uris.add(new File(pathToFolder + fileName).toURI());
ApplyChanges();
}
private void ApplyChanges() {
logger.info("Applying log4j configuration settings");
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
initialize = Configurator.initialize(null, null, uris, null);
ctx.updateLoggers();
}
{code}
I can't understand how should I use Configurator.initialize. Please, help me.
was:
I wanna add other configuration for loggers. For example, we have:
log4j2.xml
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration shutdownHook="disable"
monitorInterval="30">
<Appenders>
<File name="MyFile" fileName="all.log" immediateFlush="true" append="false">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level
%logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="ALL" additivity="false">
<AppenderRef ref="MyFile" />
</Root>
</Loggers>
</Configuration>
{code}
And we have the folder where we can add some XML, for example:
Console.xml
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration shutdownHook="disable">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="[%highlight{%-5level}] %d{DEFAULT} %c{1}.%M() -
%msg%n%throwable{short.lineNumber}" />
</Console>
</Appenders>
<Loggers>
<Root level="ALL" additivity="false">
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>{code}
I wanna understanding how apply this config to loggers. I have WatchService
and the code, which doesn't work:
{code:java}
private void AddConfiguration(String fileName) {
logger.info("Adding log4j configuration settings");
uris.add(new File(pathToFolder + fileName).toURI());
ApplyChanges();
}
private void ApplyChanges() {
logger.info("Applying log4j configuration settings");
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
initialize = Configurator.initialize(null, null, uris, null);
ctx.updateLoggers();
}
{code}
I can't understand how should I use Configurator.initialize. Please, help me.
> How does add other configuration XML files on runtime ?
> -------------------------------------------------------
>
> Key: LOG4J2-2381
> URL: https://issues.apache.org/jira/browse/LOG4J2-2381
> Project: Log4j 2
> Issue Type: Question
> Reporter: nanshakov
> Priority: Major
>
> I wanna add other configuration for loggers. For example, we have:
> log4j2.xml
> {code:java}
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration shutdownHook="disable"
> monitorInterval="30">
> <Appenders>
> <File name="MyFile" fileName="all.log" immediateFlush="true"
> append="false">
> <PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level
> %logger{36} - %msg%n"/>
> </File>
> </Appenders>
> <Loggers>
> <Root level="ALL" additivity="false">
> <AppenderRef ref="MyFile" />
> </Root>
> </Loggers>
> </Configuration>
> {code}
> And we have the folder where we can add some XML, for example:
> Console.xml
> {code:java}
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration shutdownHook="disable">
> <Appenders>
> <Console name="console" target="SYSTEM_OUT">
> <PatternLayout pattern="[%highlight{%-5level}] %d{DEFAULT} %c{1}.%M() -
> %msg%n%throwable{short.lineNumber}" />
> </Console>
> </Appenders>
> <Loggers>
> <Root level="ALL" additivity="false">
> <AppenderRef ref="console" />
> </Root>
> </Loggers>
> </Configuration>{code}
> I wanna understanding how apply this config to loggers. I have WatchService
> and the code, which doesn't work:
>
> {code:java}
> private void AddConfiguration(String fileName) {
> logger.info("Adding log4j configuration settings");
> uris.add(new File(pathToFolder + fileName).toURI());
> ApplyChanges();
> }
> private void ApplyChanges() {
> logger.info("Applying log4j configuration settings");
> LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
> initialize = Configurator.initialize(null, null, uris, null);
> ctx.updateLoggers();
> }
> {code}
> I can't understand how should I use Configurator.initialize. Please, help me.
>
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)