You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Peter Lee <to...@shaw.ca> on 2002/12/02 02:05:59 UTC

Logging to catalina logger

How  do I produce log output to the catalina loggerwhen my program wants to print out 
some exceptions or messages? Any documents on this?

Thanks

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Logging to catalina logger

Posted by Triptpal Singh Lamba <tr...@cs.sunysb.edu>.
I dont know abt the cataline logger,I am using a small method I wrote and it
is working fine right now.



import java.io.FileWriter;

import java.io.IOException;

import java.util.Calendar;

import java.util.TimeZone;

public class Logger {

static FileWriter out = null;

static String filePath = "";

public boolean pathFound =false;


public void setPath(String path) {

System.out.println("Path for logger set = " + path);

this.pathFound = true ;

filePath = path;

}



synchronized public static void log(String message) {

try {

Calendar cal = Calendar.getInstance(TimeZone.getDefault());

String DATE_FORMAT = "dd_MM_yyyy";

java.text.SimpleDateFormat sdf =

new java.text.SimpleDateFormat(DATE_FORMAT);

if (out == null) {

out =

new FileWriter(

filePath

+ "ospLogs"

+ sdf.format(cal.getTime())

+ ".txt",

true);

System.out.println(

"Path we made is = "

+ filePath

+ "ospLogs"

+ sdf.format(cal.getTime())

+ ".txt");

}

out.write(message + "\n");

out.flush();

} catch (IOException e) {

System.out.println(

"Caught IOException in logger = " + e.getMessage());

} catch (Exception e) {

System.out.println(

"Caught General Exception in logger " + e.getMessage());

}

}

}

----- Original Message -----
From: "Peter Lee" <to...@shaw.ca>
To: <to...@jakarta.apache.org>
Sent: Sunday, December 01, 2002 8:05 PM
Subject: Logging to catalina logger


> How  do I produce log output to the catalina loggerwhen my program wants
to print out
> some exceptions or messages? Any documents on this?
>
> Thanks
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Logging to catalina logger

Posted by Jon Eaves <jo...@eaves.org>.
Hi Peter,

I'm rapidly coming to the conclusion that Tomcat is the Perl of the
web application development environments.  For those who aren't
familiar with Larry Wall's quote on doing things in Perl, it's
"There's always more than one way to do it".

Starting at the top:

1. Use the log() method
2. Use System.out/err and set Context.swallowOutput to true
3. Use the Standard Error Logger and Standard Output Logger

I suspect you probably want to use 2 or 3.

All this information is available in the wonderful documentation
provided by the Tomcat developers when you download the Tomcat
installation.  It's just a matter of reading them .....

The log() method is defined in the ServletContext class in the J2EE
documentation.

#2 is documented in the Reference/Context section of the Tomcat
documentation.

#3 is documented in the Reference/Logger section of the Tomcat
documentation.

Cheers,
	-- jon


Peter Lee wrote:
> How  do I produce log output to the catalina loggerwhen my program wants to print out 
> some exceptions or messages? Any documents on this?
> 
> Thanks
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 

-- 
Jon Eaves <jo...@eaves.org>
http://www.eaves.org/jon/


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Logging to catalina logger

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Sun, 1 Dec 2002, Peter Lee wrote:

> Date: Sun, 01 Dec 2002 17:05:59 -0800
> From: Peter Lee <to...@shaw.ca>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
>      tomcatuser@shaw.ca
> To: tomcat-user@jakarta.apache.org
> Subject: Logging to catalina logger
>
> How  do I produce log output to the catalina loggerwhen my program wants to print out
> some exceptions or messages? Any documents on this?
>

Any output your servlet generates via ServletContext.log() goes here.

> Thanks



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>