Hi,

>Yes, thanx Yoav, I am in fact using Log4J for webapplication specific
>logging, with very good results.

Glad to hear it ;)

>
>But sometimes exceptions occure where they should not occure (where
they
>are not caught), and  I get stacktraces printed out on to the tomcat
>console, but no information in wich application the problem happens,
only
>what kind of error and in which class.

This is a difficult use-case. ;(  

It may be the easiest way in the long term if you could ensure every
exception is caught?  Typically, the only uncaught exceptions should be
tomcat ones like ClassNotFoundException.  All the ones in your
application should be caught (even if only rethrow them with a different
message or exception).

>Can I configure Log4J to take everything that is printed to stdout and
>apply a pattern to it and write out to a file ?

So let's assume you already have a log file with a log4j FileAppender
(named "LogFileAppender") configured to use this file.  You've
initialized log4j.

Logger rootLogger = Logger.getRootLogger();
Appender myFileAppender = rootLogger.getAppender("LogFileAppender");
String filePath = myFileAppender.getFile();
FileOutputStream fos = new FileOutputStream(filePath);
PrintStream pos = new PrintStream(fos);
System.setOut(pos);

Would the above, combined with adding the app name as an MDC attribute
in log4j (in the pattern for LogFileAppender), do the trick for you?

Just to clarify: I much prefer catching everything properly, not playing
with the above or with Tomcat's swallowOutput() flag in the <Context>
element.  But if you can't catch everything, the above hack might help
;)

Of course, you would see all the other console messages in your log
file, and things may be written out of order, but the above just came to
mind (I've never tried it myself) ;)

Yoav Shapira
Millennium ChemInformatics

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to