Ah ... Light dawns... So (ripping the printlns out into methods)
int countOfLoggers = 0; Enumeration loggers = LogManager.getLoggerRepository().getCurrentLoggers(); if(loggers != null){ while(loggers.hasMoreElements()){ Logger l = (Logger)loggers.nextElement(); if(null != l) reportLogger(l, ++countOfLoggers); } } Logger l = LogManager.getRootLogger(); if(null != l) reportLogger(l, ++countOfLoggers); Gives: Logger #1 is test getAllAppenders() returned org.apache.log4j.helpers.NullEnumeration Logger #2 is root Appender 1 test is FileAppender somethingelse.log Maybe the JavaDoc for getAllAppenders needs to be clarified? Thanks, all, for the help! -----Burton -----Original Message----- From: Paul Smith [mailto:[EMAIL PROTECTED] Sent: Thursday, December 01, 2005 10:15 PM To: Log4J Users List Subject: Re: Silly ? - How do I figure out the name of the file the log is being written to? Ok, my brain took far longer to work this out than it should of. The issue here is that the Appender is attached to the Root logger, not the Logger named 'test'. What you see is the additivity property working for you (or against you, depending on your point of view). The 'test' appender is attached to the Root logger, but any log message sent to the "test" logger goes to all appenders attached to the test logger, PLUS any up the hierarchy, right up to the Root logger. This is a feature of log4j, and can be disabled by setting the additivity property of a Logger to false. I guess getAllAppenders()'s name has confused you. It does not get "All appenders that may be used by this logger during logging", it returns "All appenders explicitly added to _this_ logger only." Hope that helps you. Paul On 02/12/2005, at 9:27 AM, Burton Strauss wrote: > Nope, it's the same log4j.properties. I had an old one lying around > in NetBeans which was the 'same' except the name wasn't test, it was a > company name. That was what was being picked up, so that's why 'test' > didn't work - > but 'xyzcorp' did. I found this when I changed the name from > testbed.log to somethingelse.log and it didn't change. > > So I've gotten past the point of being able to figure out the name of > the specific instance if I know it. > > What I can't get is the generic case, where I'm walking enumeration of > loggers and checking each of them for their associated appenders. > > So please throw away ANYTHING beyond my last message. > > Log4j.properties------------------- > log4j.rootLogger=info,test > log4j.appender.test=org.apache.log4j.DailyRollingFileAppender > log4j.appender.test.Append=false > log4j.appender.test.File=somethingelse.log > log4j.appender.test.layout=org.apache.log4j.SimpleLayout > log4j.debug=true > ----------------------------------- > > Source----------------------------- > public static void main(String[] args) { > Logger logger = null; > logger = logger.getLogger("test"); > logger.info("Beginning logger test"); > int countOfLoggers = 0; > Enumeration loggers = > LogManager.getLoggerRepository().getCurrentLoggers(); > if(loggers != null){ > while(loggers.hasMoreElements()){ > Logger l = (Logger)loggers.nextElement(); > System.out.println("Logger #" + (++countOfLoggers) + " is " + > l.getName()); > int countOfAppenders = 0; > Enumeration allAppenders = l.getAllAppenders(); > if(null == allAppenders) { > System.out.println("\tgetAllAppenders() returned null"); > continue; > } > if(allAppenders instanceof > org.apache.log4j.helpers.NullEnumeration) > { > System.out.println("\tgetAllAppenders() returned > NullEnumeration"); > continue; > } > > while(allAppenders.hasMoreElements()){ > Appender t = (Appender)allAppenders.nextElement(); > > if(null == t) { > System.out.println("\tAppender is null"); > } else { > countOfAppenders++; > if(t instanceof FileAppender) { > FileAppender fileAppender = (FileAppender)t; > System.out.println("\tAppender " + countOfAppenders + " > " + > t.getName() + " is FileAppender " + > fileAppender.getFile()); > } else { > System.out.println("\tAppender " + countOfAppenders + " > " + > t.getName() + " is something else"); > } > } > } > } > } > } > } > ----------------------------------- > > Output----------------------------- > log4j: Parsing for [root] with value=[info,test]. > log4j: Level token is [info]. > log4j: Category root set to INFO > log4j: Parsing appender named "test". > log4j: Parsing layout options for "test". > log4j: End of parsing for "test". > log4j: Setting property [file] to [somethingelse.log]. > log4j: Setting property [append] to [false]. > log4j: setFile called: somethingelse.log, false > log4j: setFile ended > log4j: Appender [test] to be rolled at midnight. > log4j: Parsed "test" options. > log4j: Finished configuring. > Logger #1 is test > getAllAppenders() returned NullEnumeration > ----------------------------------- > > TIA! > > -----Burton > > -----Original Message----- > From: Paul Smith [mailto:[EMAIL PROTECTED] > Sent: Thursday, December 01, 2005 3:36 PM > To: Log4J Users List > Subject: Re: Silly ? - How do I figure out the name of the file the > log is being written to? > > > On 02/12/2005, at 8:03 AM, Burton Strauss wrote: > >> That's easy ... console output is from System.out.println(). How >> else are you going to test the logger if you can't trust it... :-) > > Umm, in your original post you had log4j logging in the test: > Appender t = LogManager.getRootLogger().getAppender( "test"); > if(null == t) { > logger.info("LogManager.getRootLogger().getAppender(\"test > \") is > null"); > } else if(t instanceof FileAppender) { > logger.info("LogManager.getRootLogger().getAppender(\"test > \") is > FileAppender"); > } else { > logger.info("LogManager.getRootLogger().getAppender(\"test > \") is > something else"); > } > >> >> >> But the other path still fails. I expanded the test program to this: >> >> public static void main(String[] args) { >> Logger logger = null; >> logger = logger.getLogger("test"); >> logger.info("Beginning logger test"); >> int countOfLoggers = 0; >> Enumeration loggers = >> LogManager.getLoggerRepository().getCurrentLoggers(); >> if(loggers != null){ >> while(loggers.hasMoreElements()){ > </snip> > > Ok, in this test you have gotten rid of your log4j.properties.... > Correct? If so, then where is the configuration of actually > _adding_ the > FileAppender ? Or what _is_ configuring log4j in this test? > > Paul > > > --------------------------------------------------------------------- > 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]