dynamic logging control

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

dynamic logging control

Benson Margulies
In old log4j, I've  maintained a JUnit rule that temporarily throttles a logger.

In log4j2, I see a setLevel, but no getLevel, which rather screws up
'temporarily'.

What am I missing?
Reply | Threaded
Open this post in threaded view
|

Re: dynamic logging control

Ralph Goers
Are you looking at the Logger or LoggerConfig.  Log4j 2 separates Loggers from their configuration.

To modify a logLevel you need to do:

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

This process locates the configured Logger for the desired logger name, sets its level and then modifies all the Loggers that use the LoggerConfig.

Ralph

> On Nov 8, 2016, at 6:51 AM, Benson Margulies <[hidden email]> wrote:
>
> In old log4j, I've  maintained a JUnit rule that temporarily throttles a logger.
>
> In log4j2, I see a setLevel, but no getLevel, which rather screws up
> 'temporarily'.
>
> What am I missing?
>


Reply | Threaded
Open this post in threaded view
|

Re: dynamic logging control

Benson Margulies
I read http://logging.apache.org/log4j/2.x/manual/migration.html which
is how I got into the neighborhood of

org.apache.logging.log4j.core.config.Configurator.setLevel

I can follow your recipe instead.



On Tue, Nov 8, 2016 at 9:05 AM, Ralph Goers <[hidden email]> wrote:

> Are you looking at the Logger or LoggerConfig.  Log4j 2 separates Loggers from their configuration.
>
> To modify a logLevel you need to do:
>
> LoggerContext context = (LoggerContext) LogManager.getContext(false);
> Configuration config = context.getConfiguration();
> LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
> loggerConfig.setLevel(level);
> context.updateLoggers();
>
> This process locates the configured Logger for the desired logger name, sets its level and then modifies all the Loggers that use the LoggerConfig.
>
> Ralph
>
>> On Nov 8, 2016, at 6:51 AM, Benson Margulies <[hidden email]> wrote:
>>
>> In old log4j, I've  maintained a JUnit rule that temporarily throttles a logger.
>>
>> In log4j2, I see a setLevel, but no getLevel, which rather screws up
>> 'temporarily'.
>>
>> What am I missing?
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: dynamic logging control

Benson Margulies
The need to add xml-apis to the dependency tree was also a bit of a surprise.


On Tue, Nov 8, 2016 at 9:10 AM, Benson Margulies <[hidden email]> wrote:

> I read http://logging.apache.org/log4j/2.x/manual/migration.html which
> is how I got into the neighborhood of
>
> org.apache.logging.log4j.core.config.Configurator.setLevel
>
> I can follow your recipe instead.
>
>
>
> On Tue, Nov 8, 2016 at 9:05 AM, Ralph Goers <[hidden email]> wrote:
>> Are you looking at the Logger or LoggerConfig.  Log4j 2 separates Loggers from their configuration.
>>
>> To modify a logLevel you need to do:
>>
>> LoggerContext context = (LoggerContext) LogManager.getContext(false);
>> Configuration config = context.getConfiguration();
>> LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
>> loggerConfig.setLevel(level);
>> context.updateLoggers();
>>
>> This process locates the configured Logger for the desired logger name, sets its level and then modifies all the Loggers that use the LoggerConfig.
>>
>> Ralph
>>
>>> On Nov 8, 2016, at 6:51 AM, Benson Margulies <[hidden email]> wrote:
>>>
>>> In old log4j, I've  maintained a JUnit rule that temporarily throttles a logger.
>>>
>>> In log4j2, I see a setLevel, but no getLevel, which rather screws up
>>> 'temporarily'.
>>>
>>> What am I missing?
>>>
>>
>>
Reply | Threaded
Open this post in threaded view
|

Re: dynamic logging control

Ralph Goers
In reply to this post by Benson Margulies
Actually, Configurator.setLevel(loggerName, level) does all that for you.

Ralph

> On Nov 8, 2016, at 7:10 AM, Benson Margulies <[hidden email]> wrote:
>
> I read http://logging.apache.org/log4j/2.x/manual/migration.html which
> is how I got into the neighborhood of
>
> org.apache.logging.log4j.core.config.Configurator.setLevel
>
> I can follow your recipe instead.
>
>
>
> On Tue, Nov 8, 2016 at 9:05 AM, Ralph Goers <[hidden email]> wrote:
>> Are you looking at the Logger or LoggerConfig.  Log4j 2 separates Loggers from their configuration.
>>
>> To modify a logLevel you need to do:
>>
>> LoggerContext context = (LoggerContext) LogManager.getContext(false);
>> Configuration config = context.getConfiguration();
>> LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
>> loggerConfig.setLevel(level);
>> context.updateLoggers();
>>
>> This process locates the configured Logger for the desired logger name, sets its level and then modifies all the Loggers that use the LoggerConfig.
>>
>> Ralph
>>
>>> On Nov 8, 2016, at 6:51 AM, Benson Margulies <[hidden email]> wrote:
>>>
>>> In old log4j, I've  maintained a JUnit rule that temporarily throttles a logger.
>>>
>>> In log4j2, I see a setLevel, but no getLevel, which rather screws up
>>> 'temporarily'.
>>>
>>> What am I missing?
>>>
>>
>>
>


Reply | Threaded
Open this post in threaded view
|

Re: dynamic logging control

Ralph Goers
In reply to this post by Benson Margulies
What is xml-apis required for? If you need it then we have a problem.

Ralph

> On Nov 8, 2016, at 7:13 AM, Benson Margulies <[hidden email]> wrote:
>
> The need to add xml-apis to the dependency tree was also a bit of a surprise.
>
>
> On Tue, Nov 8, 2016 at 9:10 AM, Benson Margulies <[hidden email]> wrote:
>> I read http://logging.apache.org/log4j/2.x/manual/migration.html which
>> is how I got into the neighborhood of
>>
>> org.apache.logging.log4j.core.config.Configurator.setLevel
>>
>> I can follow your recipe instead.
>>
>>
>>
>> On Tue, Nov 8, 2016 at 9:05 AM, Ralph Goers <[hidden email]> wrote:
>>> Are you looking at the Logger or LoggerConfig.  Log4j 2 separates Loggers from their configuration.
>>>
>>> To modify a logLevel you need to do:
>>>
>>> LoggerContext context = (LoggerContext) LogManager.getContext(false);
>>> Configuration config = context.getConfiguration();
>>> LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
>>> loggerConfig.setLevel(level);
>>> context.updateLoggers();
>>>
>>> This process locates the configured Logger for the desired logger name, sets its level and then modifies all the Loggers that use the LoggerConfig.
>>>
>>> Ralph
>>>
>>>> On Nov 8, 2016, at 6:51 AM, Benson Margulies <[hidden email]> wrote:
>>>>
>>>> In old log4j, I've  maintained a JUnit rule that temporarily throttles a logger.
>>>>
>>>> In log4j2, I see a setLevel, but no getLevel, which rather screws up
>>>> 'temporarily'.
>>>>
>>>> What am I missing?
>>>>
>>>
>>>
>


Reply | Threaded
Open this post in threaded view
|

Re: dynamic logging control

Benson Margulies

ElementTraversal


On Nov 8, 2016 9:34 AM, "Ralph Goers" <[hidden email]> wrote:
What is xml-apis required for? If you need it then we have a problem.

Ralph

> On Nov 8, 2016, at 7:13 AM, Benson Margulies <[hidden email]> wrote:
>
> The need to add xml-apis to the dependency tree was also a bit of a surprise.
>
>
> On Tue, Nov 8, 2016 at 9:10 AM, Benson Margulies <[hidden email]> wrote:
>> I read http://logging.apache.org/log4j/2.x/manual/migration.html which
>> is how I got into the neighborhood of
>>
>> org.apache.logging.log4j.core.config.Configurator.setLevel
>>
>> I can follow your recipe instead.
>>
>>
>>
>> On Tue, Nov 8, 2016 at 9:05 AM, Ralph Goers <[hidden email]> wrote:
>>> Are you looking at the Logger or LoggerConfig.  Log4j 2 separates Loggers from their configuration.
>>>
>>> To modify a logLevel you need to do:
>>>
>>> LoggerContext context = (LoggerContext) LogManager.getContext(false);
>>> Configuration config = context.getConfiguration();
>>> LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
>>> loggerConfig.setLevel(level);
>>> context.updateLoggers();
>>>
>>> This process locates the configured Logger for the desired logger name, sets its level and then modifies all the Loggers that use the LoggerConfig.
>>>
>>> Ralph
>>>
>>>> On Nov 8, 2016, at 6:51 AM, Benson Margulies <[hidden email]> wrote:
>>>>
>>>> In old log4j, I've  maintained a JUnit rule that temporarily throttles a logger.
>>>>
>>>> In log4j2, I see a setLevel, but no getLevel, which rather screws up
>>>> 'temporarily'.
>>>>
>>>> What am I missing?
>>>>
>>>
>>>
>


Reply | Threaded
Open this post in threaded view
|

Re: dynamic logging control

Ralph Goers
I’m not sure I understand. ElementTraversal is not a class so I am assuming you mean it as a generic concept?  Do you know where we are traversing elements and require xml-apis?  Also, I don’t see xml-apis declared as a dependency in log4j-core.

Ralph

On Nov 8, 2016, at 7:46 AM, Benson Margulies <[hidden email]> wrote:

ElementTraversal


On Nov 8, 2016 9:34 AM, "Ralph Goers" <[hidden email]> wrote:
What is xml-apis required for? If you need it then we have a problem.

Ralph

> On Nov 8, 2016, at 7:13 AM, Benson Margulies <[hidden email]> wrote:
>
> The need to add xml-apis to the dependency tree was also a bit of a surprise.
>
>
> On Tue, Nov 8, 2016 at 9:10 AM, Benson Margulies <[hidden email]> wrote:
>> I read http://logging.apache.org/log4j/2.x/manual/migration.html which
>> is how I got into the neighborhood of
>>
>> org.apache.logging.log4j.core.config.Configurator.setLevel
>>
>> I can follow your recipe instead.
>>
>>
>>
>> On Tue, Nov 8, 2016 at 9:05 AM, Ralph Goers <[hidden email]> wrote:
>>> Are you looking at the Logger or LoggerConfig.  Log4j 2 separates Loggers from their configuration.
>>>
>>> To modify a logLevel you need to do:
>>>
>>> LoggerContext context = (LoggerContext) LogManager.getContext(false);
>>> Configuration config = context.getConfiguration();
>>> LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
>>> loggerConfig.setLevel(level);
>>> context.updateLoggers();
>>>
>>> This process locates the configured Logger for the desired logger name, sets its level and then modifies all the Loggers that use the LoggerConfig.
>>>
>>> Ralph
>>>
>>>> On Nov 8, 2016, at 6:51 AM, Benson Margulies <[hidden email]> wrote:
>>>>
>>>> In old log4j, I've  maintained a JUnit rule that temporarily throttles a logger.
>>>>
>>>> In log4j2, I see a setLevel, but no getLevel, which rather screws up
>>>> 'temporarily'.
>>>>
>>>> What am I missing?
>>>>
>>>
>>>
>



Reply | Threaded
Open this post in threaded view
|

Re: dynamic logging control

Benson Margulies
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.xerces.parsers.AbstractDOMParser.startDocument(Unknown Source)
at org.apache.xerces.xinclude.XIncludeHandler.startDocument(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:96)
at org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:46)
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:519)
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:455)
at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:265)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:599)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:620)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:226)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:242)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)

On Tue, Nov 8, 2016 at 9:54 AM, Ralph Goers <[hidden email]> wrote:

> I’m not sure I understand. ElementTraversal is not a class so I am assuming
> you mean it as a generic concept?  Do you know where we are traversing
> elements and require xml-apis?  Also, I don’t see xml-apis declared as a
> dependency in log4j-core.
>
> Ralph
>
> On Nov 8, 2016, at 7:46 AM, Benson Margulies <[hidden email]> wrote:
>
> ElementTraversal
>
>
> On Nov 8, 2016 9:34 AM, "Ralph Goers" <[hidden email]> wrote:
>>
>> What is xml-apis required for? If you need it then we have a problem.
>>
>> Ralph
>>
>> > On Nov 8, 2016, at 7:13 AM, Benson Margulies <[hidden email]>
>> > wrote:
>> >
>> > The need to add xml-apis to the dependency tree was also a bit of a
>> > surprise.
>> >
>> >
>> > On Tue, Nov 8, 2016 at 9:10 AM, Benson Margulies <[hidden email]>
>> > wrote:
>> >> I read http://logging.apache.org/log4j/2.x/manual/migration.html which
>> >> is how I got into the neighborhood of
>> >>
>> >> org.apache.logging.log4j.core.config.Configurator.setLevel
>> >>
>> >> I can follow your recipe instead.
>> >>
>> >>
>> >>
>> >> On Tue, Nov 8, 2016 at 9:05 AM, Ralph Goers
>> >> <[hidden email]> wrote:
>> >>> Are you looking at the Logger or LoggerConfig.  Log4j 2 separates
>> >>> Loggers from their configuration.
>> >>>
>> >>> To modify a logLevel you need to do:
>> >>>
>> >>> LoggerContext context = (LoggerContext) LogManager.getContext(false);
>> >>> Configuration config = context.getConfiguration();
>> >>> LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
>> >>> loggerConfig.setLevel(level);
>> >>> context.updateLoggers();
>> >>>
>> >>> This process locates the configured Logger for the desired logger
>> >>> name, sets its level and then modifies all the Loggers that use the
>> >>> LoggerConfig.
>> >>>
>> >>> Ralph
>> >>>
>> >>>> On Nov 8, 2016, at 6:51 AM, Benson Margulies <[hidden email]>
>> >>>> wrote:
>> >>>>
>> >>>> In old log4j, I've  maintained a JUnit rule that temporarily
>> >>>> throttles a logger.
>> >>>>
>> >>>> In log4j2, I see a setLevel, but no getLevel, which rather screws up
>> >>>> 'temporarily'.
>> >>>>
>> >>>> What am I missing?
>> >>>>
>> >>>
>> >>>
>> >
>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: dynamic logging control

Benson Margulies
I see. this particular thing has xerces in the classpath.


On Tue, Nov 8, 2016 at 10:49 AM, Benson Margulies <[hidden email]> wrote:

> Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
> at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> at java.lang.ClassLoader.defineClass1(Native Method)
> at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
> at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
> at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
> at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
> at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
> at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> at org.apache.xerces.parsers.AbstractDOMParser.startDocument(Unknown Source)
> at org.apache.xerces.xinclude.XIncludeHandler.startDocument(Unknown Source)
> at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source)
> at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown Source)
> at org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown
> Source)
> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
> at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
> at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
> at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
> at org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:96)
> at org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:46)
> at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:519)
> at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:455)
> at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:265)
> at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:599)
> at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:620)
> at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:226)
> at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:242)
> at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
>
> On Tue, Nov 8, 2016 at 9:54 AM, Ralph Goers <[hidden email]> wrote:
>> I’m not sure I understand. ElementTraversal is not a class so I am assuming
>> you mean it as a generic concept?  Do you know where we are traversing
>> elements and require xml-apis?  Also, I don’t see xml-apis declared as a
>> dependency in log4j-core.
>>
>> Ralph
>>
>> On Nov 8, 2016, at 7:46 AM, Benson Margulies <[hidden email]> wrote:
>>
>> ElementTraversal
>>
>>
>> On Nov 8, 2016 9:34 AM, "Ralph Goers" <[hidden email]> wrote:
>>>
>>> What is xml-apis required for? If you need it then we have a problem.
>>>
>>> Ralph
>>>
>>> > On Nov 8, 2016, at 7:13 AM, Benson Margulies <[hidden email]>
>>> > wrote:
>>> >
>>> > The need to add xml-apis to the dependency tree was also a bit of a
>>> > surprise.
>>> >
>>> >
>>> > On Tue, Nov 8, 2016 at 9:10 AM, Benson Margulies <[hidden email]>
>>> > wrote:
>>> >> I read http://logging.apache.org/log4j/2.x/manual/migration.html which
>>> >> is how I got into the neighborhood of
>>> >>
>>> >> org.apache.logging.log4j.core.config.Configurator.setLevel
>>> >>
>>> >> I can follow your recipe instead.
>>> >>
>>> >>
>>> >>
>>> >> On Tue, Nov 8, 2016 at 9:05 AM, Ralph Goers
>>> >> <[hidden email]> wrote:
>>> >>> Are you looking at the Logger or LoggerConfig.  Log4j 2 separates
>>> >>> Loggers from their configuration.
>>> >>>
>>> >>> To modify a logLevel you need to do:
>>> >>>
>>> >>> LoggerContext context = (LoggerContext) LogManager.getContext(false);
>>> >>> Configuration config = context.getConfiguration();
>>> >>> LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
>>> >>> loggerConfig.setLevel(level);
>>> >>> context.updateLoggers();
>>> >>>
>>> >>> This process locates the configured Logger for the desired logger
>>> >>> name, sets its level and then modifies all the Loggers that use the
>>> >>> LoggerConfig.
>>> >>>
>>> >>> Ralph
>>> >>>
>>> >>>> On Nov 8, 2016, at 6:51 AM, Benson Margulies <[hidden email]>
>>> >>>> wrote:
>>> >>>>
>>> >>>> In old log4j, I've  maintained a JUnit rule that temporarily
>>> >>>> throttles a logger.
>>> >>>>
>>> >>>> In log4j2, I see a setLevel, but no getLevel, which rather screws up
>>> >>>> 'temporarily'.
>>> >>>>
>>> >>>> What am I missing?
>>> >>>>
>>> >>>
>>> >>>
>>> >
>>>
>>>
>>
Reply | Threaded
Open this post in threaded view
|

Re: dynamic logging control

Benson Margulies
In reply to this post by Ralph Goers
On Tue, Nov 8, 2016 at 9:33 AM, Ralph Goers <[hidden email]> wrote:
> Actually, Configurator.setLevel(loggerName, level) does all that for you.

Yes, and it it returned the old level, I wouldn't have needed to start
this thread.

>
> Ralph
>
>> On Nov 8, 2016, at 7:10 AM, Benson Margulies <[hidden email]> wrote:
>>
>> I read http://logging.apache.org/log4j/2.x/manual/migration.html which
>> is how I got into the neighborhood of
>>
>> org.apache.logging.log4j.core.config.Configurator.setLevel
>>
>> I can follow your recipe instead.
>>
>>
>>
>> On Tue, Nov 8, 2016 at 9:05 AM, Ralph Goers <[hidden email]> wrote:
>>> Are you looking at the Logger or LoggerConfig.  Log4j 2 separates Loggers from their configuration.
>>>
>>> To modify a logLevel you need to do:
>>>
>>> LoggerContext context = (LoggerContext) LogManager.getContext(false);
>>> Configuration config = context.getConfiguration();
>>> LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
>>> loggerConfig.setLevel(level);
>>> context.updateLoggers();
>>>
>>> This process locates the configured Logger for the desired logger name, sets its level and then modifies all the Loggers that use the LoggerConfig.
>>>
>>> Ralph
>>>
>>>> On Nov 8, 2016, at 6:51 AM, Benson Margulies <[hidden email]> wrote:
>>>>
>>>> In old log4j, I've  maintained a JUnit rule that temporarily throttles a logger.
>>>>
>>>> In log4j2, I see a setLevel, but no getLevel, which rather screws up
>>>> 'temporarily'.
>>>>
>>>> What am I missing?
>>>>
>>>
>>>
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: dynamic logging control

Gary Gregory-4

Maybe we need to publicize the Configuator class a little better?

Gary


On Nov 8, 2016 7:51 AM, "Benson Margulies" <[hidden email]> wrote:
On Tue, Nov 8, 2016 at 9:33 AM, Ralph Goers <[hidden email]> wrote:
> Actually, Configurator.setLevel(loggerName, level) does all that for you.

Yes, and it it returned the old level, I wouldn't have needed to start
this thread.

>
> Ralph
>
>> On Nov 8, 2016, at 7:10 AM, Benson Margulies <[hidden email]> wrote:
>>
>> I read http://logging.apache.org/log4j/2.x/manual/migration.html which
>> is how I got into the neighborhood of
>>
>> org.apache.logging.log4j.core.config.Configurator.setLevel
>>
>> I can follow your recipe instead.
>>
>>
>>
>> On Tue, Nov 8, 2016 at 9:05 AM, Ralph Goers <[hidden email]> wrote:
>>> Are you looking at the Logger or LoggerConfig.  Log4j 2 separates Loggers from their configuration.
>>>
>>> To modify a logLevel you need to do:
>>>
>>> LoggerContext context = (LoggerContext) LogManager.getContext(false);
>>> Configuration config = context.getConfiguration();
>>> LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
>>> loggerConfig.setLevel(level);
>>> context.updateLoggers();
>>>
>>> This process locates the configured Logger for the desired logger name, sets its level and then modifies all the Loggers that use the LoggerConfig.
>>>
>>> Ralph
>>>
>>>> On Nov 8, 2016, at 6:51 AM, Benson Margulies <[hidden email]> wrote:
>>>>
>>>> In old log4j, I've  maintained a JUnit rule that temporarily throttles a logger.
>>>>
>>>> In log4j2, I see a setLevel, but no getLevel, which rather screws up
>>>> 'temporarily'.
>>>>
>>>> What am I missing?
>>>>
>>>
>>>
>>
>
>