logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Alexander.Rat...@materna.de>
Subject AW: AW: How to get loggers configured in log4j2.xml
Date Thu, 24 Oct 2013 13:31:43 GMT
Hi,
LoggerContext should be used. It's implemented the right way there:
public boolean hasLogger(final String name) {
        return loggers.containsKey(name);
    }

If you use getLogger - a logger will be created if it doesn't exist yet.
There is no getLoggers() function.

I was asking to check the debug output so you can verify that the logger is actually created
- It could be a misconfiguration.

Best Regards,
Alex



-----Urspr√ľngliche Nachricht-----
Von: David KOCH [mailto:dkoch@ezakus.com] 
Gesendet: Donnerstag, 24. Oktober 2013 15:25
An: Log4J Users List
Betreff: Re: AW: How to get loggers configured in log4j2.xml

Ok, so maybe I am not getting something here but if I check SimpleLoggerContext.java<http://grepcode.com/file/repo1.maven.org/maven2/org.apache.logging.log4j/log4j-api/2.0-beta8/org/apache/logging/log4j/simple/SimpleLoggerContext.java?av=h#117>
(only
implementation of LoggerContext) then hasLogger always returns false. If instead, I do
logContext().getConfiguration().getLoggers().contains(<myLoggerName>) it works - is
there a risk?

/David


On Thu, Oct 24, 2013 at 2:31 PM, David KOCH <dkoch@ezakus.com> wrote:

> Hi,
>
> Thank you for your replies. Sure, I can look at the StatusLogger 
> output but that's not what I need to do. I need to check 
> programmatically if a logger with name X.Y.Z has been configured using 
> the configuration file I provided. Like I said, I tried instantiating 
> LoggerContexts etc. none of it worked.
>
> I feel this can't be so hard to do but I don't even know how to get 
> hold of the "default" LoggerContext which is used when the application 
> is fired up.
>
> David
>
>
> On Thu, Oct 24, 2013 at 2:19 PM, Remko Popma <remko.popma@gmail.com>wrote:
>
>> You can also check with JConsole (see the JMX docs).
>>
>> Sent from my iPhone
>>
>> > On 2013/10/24, at 21:06, <Alexander.Rathai@materna.de> wrote:
>> >
>> > Hi,
>> >
>> > Which configuration file are you using?
>> > If you're using XML try this:
>> > <Configuration
>> >    status="debug"...
>> >
>> > You should then see something along the lines of
>> >
>> > 2013-10-24 14:03:09,332 DEBUG Calling createLogger on class
>> org.apache.logging.log4j.core.config.LoggerConfig$RootLogger for 
>> element Root with params(additivity="null", level="info", 
>> includeLocation="null", AppenderRef={STDOUT, FLOW, EXCEPTION}, 
>> Properties={}, Configuration(HereWillBeYourConfigurationName), null)
>> >
>> > Does it print the name of the logger you are looking for in your
>> application?
>> >
>> >
>> > /Alex
>> >
>> >
>> >
>> > -----Urspr√ľngliche Nachricht-----
>> > Von: David KOCH [mailto:dkoch@ezakus.com]
>> > Gesendet: Donnerstag, 24. Oktober 2013 12:04
>> > An: log4j-user@logging.apache.org
>> > Betreff: How to get loggers configured in log4j2.xml
>> >
>> > Hello,
>> >
>> > How can I check inside the application if a particular logger has 
>> > been
>> configured in the log4j configuration file?
>> >
>> > LogManager.getContext(...).hasLogger(<name>) always returns "false"
>> even though I know the logger has been configured.
>> >
>> > Thank you,
>> >
>> > /David
>> >
>> > -------------------------------------------------------------------
>> > -- To unsubscribe, e-mail: 
>> > log4j-user-unsubscribe@logging.apache.org
>> > For additional commands, e-mail: log4j-user-help@logging.apache.org
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message