You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@logging.apache.org by Benson Margulies <be...@basistech.com> on 2016/11/08 13:51:16 UTC

dynamic logging control

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?

Re: dynamic logging control

Posted by Gary Gregory <ga...@gmail.com>.
Maybe we need to publicize the Configuator class a little better?

Gary

On Nov 8, 2016 7:51 AM, "Benson Margulies" <be...@basistech.com> wrote:

> On Tue, Nov 8, 2016 at 9:33 AM, Ralph Goers <ra...@dslextreme.com>
> 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 <be...@basistech.com>
> 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 <ra...@dslextreme.com>
> 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 <be...@basistech.com>
> 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?
> >>>>
> >>>
> >>>
> >>
> >
> >
>

Re: dynamic logging control

Posted by Benson Margulies <be...@basistech.com>.
On Tue, Nov 8, 2016 at 9:33 AM, Ralph Goers <ra...@dslextreme.com> 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 <be...@basistech.com> 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 <ra...@dslextreme.com> 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 <be...@basistech.com> 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?
>>>>
>>>
>>>
>>
>
>

Re: dynamic logging control

Posted by Ralph Goers <ra...@dslextreme.com>.
Actually, Configurator.setLevel(loggerName, level) does all that for you.

Ralph

> On Nov 8, 2016, at 7:10 AM, Benson Margulies <be...@basistech.com> 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 <ra...@dslextreme.com> 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 <be...@basistech.com> 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?
>>> 
>> 
>> 
> 



Re: dynamic logging control

Posted by Benson Margulies <be...@basistech.com>.
I see. this particular thing has xerces in the classpath.


On Tue, Nov 8, 2016 at 10:49 AM, Benson Margulies <be...@basistech.com> 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 <ra...@dslextreme.com> 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 <be...@basistech.com> wrote:
>>
>> ElementTraversal
>>
>>
>> On Nov 8, 2016 9:34 AM, "Ralph Goers" <ra...@dslextreme.com> 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 <be...@basistech.com>
>>> > 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 <be...@basistech.com>
>>> > 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
>>> >> <ra...@dslextreme.com> 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 <be...@basistech.com>
>>> >>>> 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?
>>> >>>>
>>> >>>
>>> >>>
>>> >
>>>
>>>
>>

Re: dynamic logging control

Posted by Benson Margulies <be...@basistech.com>.
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 <ra...@dslextreme.com> 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 <be...@basistech.com> wrote:
>
> ElementTraversal
>
>
> On Nov 8, 2016 9:34 AM, "Ralph Goers" <ra...@dslextreme.com> 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 <be...@basistech.com>
>> > 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 <be...@basistech.com>
>> > 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
>> >> <ra...@dslextreme.com> 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 <be...@basistech.com>
>> >>>> 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?
>> >>>>
>> >>>
>> >>>
>> >
>>
>>
>

Re: dynamic logging control

Posted by Ralph Goers <ra...@dslextreme.com>.
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 <be...@basistech.com> wrote:
> 
> ElementTraversal
> 
> On Nov 8, 2016 9:34 AM, "Ralph Goers" <ralph.goers@dslextreme.com <ma...@dslextreme.com>> 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 <benson@basistech.com <ma...@basistech.com>> 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 <benson@basistech.com <ma...@basistech.com>> wrote:
> >> I read http://logging.apache.org/log4j/2.x/manual/migration.html <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 <ralph.goers@dslextreme.com <ma...@dslextreme.com>> 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 <benson@basistech.com <ma...@basistech.com>> 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?
> >>>>
> >>>
> >>>
> >
> 
> 


Re: dynamic logging control

Posted by Benson Margulies <be...@basistech.com>.
ElementTraversal

On Nov 8, 2016 9:34 AM, "Ralph Goers" <ra...@dslextreme.com> 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 <be...@basistech.com>
> 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 <be...@basistech.com>
> 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 <ra...@dslextreme.com>
> 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 <be...@basistech.com>
> 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?
> >>>>
> >>>
> >>>
> >
>
>
>

Re: dynamic logging control

Posted by Ralph Goers <ra...@dslextreme.com>.
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 <be...@basistech.com> 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 <be...@basistech.com> 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 <ra...@dslextreme.com> 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 <be...@basistech.com> 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?
>>>> 
>>> 
>>> 
> 



Re: dynamic logging control

Posted by Benson Margulies <be...@basistech.com>.
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 <be...@basistech.com> 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 <ra...@dslextreme.com> 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 <be...@basistech.com> 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?
>>>
>>
>>

Re: dynamic logging control

Posted by Benson Margulies <be...@basistech.com>.
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 <ra...@dslextreme.com> 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 <be...@basistech.com> 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?
>>
>
>

Re: dynamic logging control

Posted by Ralph Goers <ra...@dslextreme.com>.
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 <be...@basistech.com> 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?
>