Discussion:
[jira] [Created] (LOG4J2-823) Changing AsyncLogger level programmatically
Pranav Pratap (JIRA)
2014-09-11 22:43:34 UTC
Permalink
Pranav Pratap created LOG4J2-823:
------------------------------------

Summary: Changing AsyncLogger level programmatically
Key: LOG4J2-823
URL: https://issues.apache.org/jira/browse/LOG4J2-823
Project: Log4j 2
Issue Type: Bug
Components: Appenders
Affects Versions: 2.0-rc2
Reporter: Pranav Pratap


I am trying to programmatically change the log level of AsyncLogger. But unable to do so.

Programmatically we can change AsyncRoot or Root Log level using below code:

LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(level);
ctx.updateLoggers();

How to achieve the same for AsyncLogger? Please suggest. I searched many forums but all provide the way for Root Level or AsyncRoot Log Level Change. But no once suggest the AsyncLogger logger level change mechanism.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Pranav Pratap (JIRA)
2014-09-12 17:05:33 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-823?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pranav Pratap closed LOG4J2-823.
--------------------------------
Resolution: Fixed
Post by Pranav Pratap (JIRA)
Changing AsyncLogger level programmatically
-------------------------------------------
Key: LOG4J2-823
URL: https://issues.apache.org/jira/browse/LOG4J2-823
Project: Log4j 2
Issue Type: Bug
Components: Appenders
Affects Versions: 2.0-rc2
Reporter: Pranav Pratap
Labels: AsyncLogger
I am trying to programmatically change the log level of AsyncLogger. But unable to do so.
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(level);
ctx.updateLoggers();
How to achieve the same for AsyncLogger? Please suggest. I searched many forums but all provide the way for Root Level or AsyncRoot Log Level Change. But no once suggest the AsyncLogger logger level change mechanism.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Pranav Pratap (JIRA)
2014-09-12 21:25:34 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-823?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pranav Pratap reopened LOG4J2-823:
----------------------------------

Synchronous logger change programmatically works but not Asynchronous Logger.
Post by Pranav Pratap (JIRA)
Changing AsyncLogger level programmatically
-------------------------------------------
Key: LOG4J2-823
URL: https://issues.apache.org/jira/browse/LOG4J2-823
Project: Log4j 2
Issue Type: Bug
Components: Appenders
Affects Versions: 2.0-rc2
Reporter: Pranav Pratap
Labels: AsyncLogger
I am trying to programmatically change the log level of AsyncLogger. But unable to do so.
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(level);
ctx.updateLoggers();
How to achieve the same for AsyncLogger? Please suggest. I searched many forums but all provide the way for Root Level or AsyncRoot Log Level Change. But no once suggest the AsyncLogger logger level change mechanism.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Pranav Pratap (JIRA)
2014-09-12 21:32:33 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-823?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14132143#comment-14132143 ]

Pranav Pratap commented on LOG4J2-823:
--------------------------------------

I am using below code for changing the root level log programmatically: This will change the Root Level Logger:

public static void chngRootLogLevel(Level level) {

LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(level);
ctx.updateLoggers();
}

I tried to use below Code for changing the logger level log, it works fine with synchronous logger i.e., for below code snippet:

<Loggers>
<Logger name="com.test.main" level="debug">
<AppenderRef ref="asyncLog" />
<appender-ref ref="RollingFile" />
</Logger>
<AsyncRoot level="error"/>
</Loggers>


public static void chngLogggerLogLevel(Level level, Logger log) {
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(log.getName());
loggerConfig.setLevel(level);
ctx.updateLoggers();
}

But the same if I try for <AsyncLogger></AsyncLogger> it does not work. Please let me know how can we change the AsyncLogger programmatically.
Post by Pranav Pratap (JIRA)
Changing AsyncLogger level programmatically
-------------------------------------------
Key: LOG4J2-823
URL: https://issues.apache.org/jira/browse/LOG4J2-823
Project: Log4j 2
Issue Type: Bug
Components: Appenders
Affects Versions: 2.0-rc2
Reporter: Pranav Pratap
Labels: AsyncLogger
I am trying to programmatically change the log level of AsyncLogger. But unable to do so.
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(level);
ctx.updateLoggers();
How to achieve the same for AsyncLogger? Please suggest. I searched many forums but all provide the way for Root Level or AsyncRoot Log Level Change. But no once suggest the AsyncLogger logger level change mechanism.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Pranav Pratap (JIRA)
2014-09-12 21:50:33 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-823?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pranav Pratap updated LOG4J2-823:
---------------------------------
Summary: Changing AsyncLogger level programmatically not working properly (was: Changing AsyncLogger level programmatically)
Changing AsyncLogger level programmatically not working properly
----------------------------------------------------------------
Key: LOG4J2-823
URL: https://issues.apache.org/jira/browse/LOG4J2-823
Project: Log4j 2
Issue Type: Bug
Components: Appenders
Affects Versions: 2.0-rc2
Reporter: Pranav Pratap
Labels: AsyncLogger
I am trying to programmatically change the log level of AsyncLogger. But unable to do so.
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(level);
ctx.updateLoggers();
How to achieve the same for AsyncLogger? Please suggest. I searched many forums but all provide the way for Root Level or AsyncRoot Log Level Change. But no once suggest the AsyncLogger logger level change mechanism.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Loading...