Hm, still no luck with LoggerContext.hasLogger(...) using LoggerContext.getConfiguration().getLoggers().containsKey(...) instead.
Thank you for your replies. /David On Thu, Oct 24, 2013 at 3:31 PM, <[email protected]> wrote: > 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:[email protected]] > 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 <[email protected]> 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 <[email protected] > >wrote: > > > >> You can also check with JConsole (see the JMX docs). > >> > >> Sent from my iPhone > >> > >> > On 2013/10/24, at 21:06, <[email protected]> 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:[email protected]] > >> > Gesendet: Donnerstag, 24. Oktober 2013 12:04 > >> > An: [email protected] > >> > 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: > >> > [email protected] > >> > For additional commands, e-mail: [email protected] > >> > > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: [email protected] > >> For additional commands, e-mail: [email protected] > >> > >> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
