Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

log4j console output

 
David Garratt
Ranch Hand
Posts: 212
Eclipse IDE Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I run my application from within Eclipse my debug output appears in the eclipse 'console' window. If I want to see this output in the dos window that opens when I run my application do I need to change the xml log4j config file ? The syntax seems a little cryptic so say the least.

Many thanks in advance.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>

<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p [%t] %c - %m%n"/>
</layout>
</appender>

<root>
<level value="debug" />
<appender-ref ref="CONSOLE" />
</root>
</log4j:configuration>
 
Joe Ess
Bartender
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Garratt:
The syntax seems a little cryptic so say the least.


If that's the most cryptic thing you ever run across, you're a VERY lucky indivudual!
I don't think you'll have to change your configuration, but you will have to tell log4j to use that configuration with a command-line parameter like this:

 
David Garratt
Ranch Hand
Posts: 212
Eclipse IDE Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I run my app via a batch file (DOS) with a command line starting

%JAVA_HOME%\bin\javaw.exe -D.\xml\log4j.xml -classpath .\bin;........

I have a utility class which has a number of methods within it one of which is this :-

public static void initLogging()
{
DOMConfigurator.configure("xml/log4j.xml");
}

This is called a the start of my application.

Any debug messages are generated as example :-

public static void test()
{
final Logger logger = Logger.getLogger(MyTest.class);

logger.debug("something meaningful");

}

These messages appear in the Eclipse "console" window when I run from the IDE, but I was rather expecting to see them in the DOS window when the app is run from the desktop direct. I have "ECHO ON" at the start of my batch file.

Should I be doing some more coding in my initLogging routine.

Thanks in advance

Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic