I used this code. To start loggin, I have to call at least one time the init
method.
I`ve created some facilities to me (at my JSP and Servlets I`m not using
System.err.println( "mensagem" ), but Log.log( "mensagem" (that`s short).
(note that messages are in Brazilian Portuguese).
----------------------------------------------------------------------------
------------------------------------------------------
package br.mycompany.common;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Date;
/**
* A Log class.
* <P>
* @author Edson Carlos Ericksson Richter
*/
public class Log extends Object {
public static PrintStream pw = null;
public static final boolean trace = true;
/**
* Constructor
*/
public static void init( ) {
try {
if( trace ) {
// I`ll write logApp.txt in root directory where
Tomcat was installed.
pw = new PrintStream( new FileOutputStream(
"/logApp.txt", true ), true );
System.setErr( pw ); // This will redirect
System.err
System.setOut( pw ); // This will redirect
System.out
}
} catch( Exception e ) {
System.err.println( "Erro durante a abertura do arquivo de Log
d:/log.txt" );
}
}
public static void log( String mensagem ) {
if( trace ) {
if( pw == null ) init( );
Date d = new Date( );
System.err.println( d.toString( ) + " " + mensagem );
}
}
public static void log( String sistema, String mensagem ) {
if( trace ) {
if( pw == null ) init( );
Date d = new Date( );
System.err.println( d.toString( ) + " " + sistema + "->" +
mensagem );
}
}
public static void log( Exception e ) {
if( trace ) {
if( pw == null ) init( );
Date d = new Date( );
System.err.println( d.toString( ) + ":" + e.getLocalizedMessage(
) );
e.printStackTrace( );
}
}
}
> ----- Mensagem original -----
> De: Alan Wright [SMTP:[EMAIL PROTECTED]]
> Enviada em: quarta-feira, 13 de dezembro de 2000 8:29
> Para: [EMAIL PROTECTED]
> Assunto: stdout logging
>
> Is it possible to force tomcat to redirect all stdout to a specified
> logfile
> for any servlets/beans that are running under tomcat?
>
> Thanks
>
> Alan Wright