<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iobound &#187; log4j</title>
	<atom:link href="http://iobound.com/tag/log4j/feed/" rel="self" type="application/rss+xml" />
	<link>http://iobound.com</link>
	<description>philip mccarthy's weblog</description>
	<lastBuildDate>Sun, 05 Sep 2010 17:17:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Finding Log4J&#8217;s Log Files</title>
		<link>http://iobound.com/2008/12/log4j-files/</link>
		<comments>http://iobound.com/2008/12/log4j-files/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 00:11:37 +0000</pubDate>
		<dc:creator>phil</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[log4j]]></category>

		<guid isPermaLink="false">http://iobound.com/?p=16</guid>
		<description><![CDATA[On a few occasions lately, I&#8217;ve logged into remote machines to look at Java log files, and then spent two minutes figuring out where to find them. I wrote this bit of code to wrangle the log file locations from the Log4J API, which I use write out the file paths to a known location [...]]]></description>
			<content:encoded><![CDATA[<p>On a few occasions lately, I&#8217;ve logged into remote machines to look at Java log files, and then spent two minutes figuring out where to find them. I wrote this bit of code to wrangle the log file locations from the Log4J API, which I use write out the file paths to a known location on startup. If you have a somewhat complex multi-environment configuration, or generate multiple log files per application, then this code snippet may prove helpful.</p>
<p>Since the Log4J API is still Enumeration-based, there are some ugly old-school loops in there. All types are from the java.util or org.apache.log4j packages.</p>
<pre class="brush: java">
@SuppressWarnings(&quot;unchecked&quot;)
private static Map&lt;String,String&gt; getLogLocations() {

  Collection&lt;Logger&gt; allLoggers = new ArrayList&lt;Logger&gt;();

  Logger rootLogger = Logger.getRootLogger();

  allLoggers.add(rootLogger);
  for (Enumeration&lt;Logger&gt; loggers =
          rootLogger.getLoggerRepository().getCurrentLoggers() ;
          loggers.hasMoreElements() ; ) {

    allLoggers.add(loggers.nextElement());
  }

  Set&lt;FileAppender&gt; fileAppenders =
        new LinkedHashSet&lt;FileAppender&gt;();

  for (Logger logger : allLoggers) {
    for (Enumeration&lt;Appender&gt; appenders =
            logger.getAllAppenders() ;
            appenders.hasMoreElements() ; ) {

      Appender appender = appenders.nextElement();
      if (appender instanceof FileAppender) {

        fileAppenders.add((FileAppender) appender);
      }
    }
  }

  Map&lt;String, String&gt; locations =
        new LinkedHashMap&lt;String,String&gt;();

  for (FileAppender appender : fileAppenders) {
    locations.put(appender.getName(), appender.getFile());
  }

  return locations;
}
</pre>
<p>The code just grabs the root logger, finds all the other loggers via its LoggerRepository, and then finds the set of all FileAppenders attached to them. It returns a Map of appender name to logfile location (both Strings), in the order they are declared in your configuration.</p>
<p>Not really the world&#8217;s most elegant code. Despite the clunky Log4J API, I can&#8217;t help thinking that would take no more than two or three lines in Python or Ruby.</p>
]]></content:encoded>
			<wfw:commentRss>http://iobound.com/2008/12/log4j-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
