You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@jakarta.apache.org by Sudheer Divakaran <su...@svw.com> on 2000/02/25 10:54:33 UTC

Is it possible to log errors to server's log file in Tomcat 3.0?

Hi all,

    I'm using Tomcat 3.0 with Apache 1.3.9(jdk1.2.2). My question is it
possible to log errors that occurs in servlets  and JSPs to Apache's error
log file?

Thanks,
Sudheer.


Re: Is it possible to log errors to server's log file in Tomcat 3.0?

Posted by Damian Fauth <df...@access.fairfax.com.au>.
I believe mod_jserv + ApacheJServ allow logging to apache's error log
only if mod_jserv is used to launch ApacheJServ when apache starts.
mod_jserv redirects the ApacheJServ process' stderr to mod_jserv.log (or
error.log if you have disabled ApJServLogFile set to DISABLED)

Are there any plans to support automated startup with Tomcat?

Damian

Sudheer Divakaran wrote:
> 
> What I said was of  Apache running along with ApacheJserv not Tomcat.  When
> I tested it on a single machine, I found both using the same log file.  But
> when I mounted TOMCAT's 'CONTEXT' in Apache, it didn't log any of the
> messages printed to System.err by TOMCAT's servlets. But of Jserv it did.
> I didn't test it on multiple machines.
> 
> Thanks
> Sudheer
> 
> > Are you sure ??? What if you have load-balancing and JServ runs on a
> > different machine? Do they send all the logs back ?
> >
> > Even for single machine, are you sure the file is used by both Apache and
> > tomcat at the same time ( i.e. do you see both your messages and apache
> > messages in that file )? It's not easy and very expensive to have 2
> > processes write to the same file.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: general-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: general-help@jakarta.apache.org

Re: Is it possible to log errors to server's log file in Tomcat 3.0?

Posted by Sudheer Divakaran <su...@svw.com>.
What I said was of  Apache running along with ApacheJserv not Tomcat.  When
I tested it on a single machine, I found both using the same log file.  But
when I mounted TOMCAT's 'CONTEXT' in Apache, it didn't log any of the
messages printed to System.err by TOMCAT's servlets. But of Jserv it did.
I didn't test it on multiple machines.

Thanks
Sudheer

> Are you sure ??? What if you have load-balancing and JServ runs on a
> different machine? Do they send all the logs back ?
>
> Even for single machine, are you sure the file is used by both Apache and
> tomcat at the same time ( i.e. do you see both your messages and apache
> messages in that file )? It's not easy and very expensive to have 2
> processes write to the same file.



Re: Is it possible to log errors to server's log file in Tomcat 3.0?

Posted by co...@eng.sun.com.
> Well.. If we are using Apache Jserv & GNU JSP  whatever we prints to
> System.err are logged to the error log file of Apache(normally error.log).

Are you sure ??? What if you have load-balancing and JServ runs on a
different machine? Do they send all the logs back ?

Even for single machine, are you sure the file is used by both Apache and
tomcat at the same time ( i.e. do you see both your messages and apache
messages in that file )? It's not easy and very expensive to have 2
processes write to the same file.

Costin 


Re: Is it possible to log errors to server's log file in Tomcat 3.0?

Posted by Sudheer Divakaran <su...@svw.com>.
Well.. If we are using Apache Jserv & GNU JSP  whatever we prints to
System.err are logged to the error log file of Apache(normally error.log).

Thanks
Sudheer

> Does it? The C side ( mod_jserv ) does, and we use the same module so we
> do it too.
>
> The Java side doesn't AFAIK, and it's not possible without a callback
> ( since the file is open and used by Apache ). A callback is a bit too
> expensive for just a log - you don't want to keep your server busy doing
> too much log processing.
>
> Costin



Re: Is it possible to log errors to server's log file in Tomcat 3.0?

Posted by co...@eng.sun.com.
> But Jserv supports 'logging to webserver's log file'. They are not
> supporting this Tomcat!!

Does it? The C side ( mod_jserv ) does, and we use the same module so we
do it too.

The Java side doesn't AFAIK, and it's not possible without a callback
( since the file is open and used by Apache ). A callback is a bit too
expensive for just a log - you don't want to keep your server busy doing
too much log processing.

Costin




Re: Is it possible to log errors to server's log file in Tomcat 3.0?

Posted by Sudheer Divakaran <su...@svw.com>.
But Jserv supports 'logging to webserver's log file'. They are not
supporting this Tomcat!!
Any Idia?

Thanks
Sudheer


Re: Is it possible to log errors to server's log file in Tomcat 3.0?

Posted by Adam Rossi <ad...@platinumsolutions.com>.
The expresso framework at www.javacorporate.com has a logging mechanism that
once wrote to a html file, but has since been upgraded to write to a
database table. The log file operations where not threadsafe and where
causing errors before the change. I have seen this happen on other servlet
projects as well, so take care if you plan on writing your own logging
classes. You might want to check out the expresso framework logging classes
and take what you need...the project is open source under an Apache style
license.

----- Original Message -----
From: "Sudheer Divakaran" <su...@svw.com>
To: <ge...@jakarta.apache.org>
Sent: Friday, February 25, 2000 4:54 AM
Subject: Is it possible to log errors to server's log file in Tomcat 3.0?


> Hi all,
>
>     I'm using Tomcat 3.0 with Apache 1.3.9(jdk1.2.2). My question is it
> possible to log errors that occurs in servlets  and JSPs to Apache's error
> log file?
>
> Thanks,
> Sudheer.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: general-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: general-help@jakarta.apache.org
>
>


Re: Is it possible to log errors to server's log file inTomcat 3.0?

Posted by Anil Vijendran <An...@eng.sun.com>.
Jose Alberto Fernandez wrote:

> So how does this work if I am running multiple VMs in the same or
> separate
> machines? Does every VM gets its own log file?

In Tomcat right now every VM (in the multiple VM case) gets its own log file.
When I implemented logging, I thought about having a logging backend into which
you could make remote calls to from any VM/process and that would generate entries
in one configurable log file (system-wide or per process or whatever) but it
seemed too heavy weight for now.

> Logging should be a done by the container. Because loggin is dependent
> of the execution environment. For example, with your class all requests
> are competing to get access to the same logging object which means your
> logging is a bottle neck to scalability. A smart container must try
> very hard to avoid having threads wayting for the log. You should
> probably need a queue of logging messages and a logger thread that takes
> the care of it.

This is exactly how it works currently.

--
Peace, Anil +<:-)




Re: Is it possible to log errors to server's log file inTomcat 3.0?

Posted by Jose Alberto Fernandez <jo...@us.oracle.com>.
So how does this work if I am running multiple VMs in the same or
separate 
machines? Does every VM gets its own log file?

Logging should be a done by the container. Because loggin is dependent
of the execution environment. For example, with your class all requests
are competing to get access to the same logging object which means your
logging is a bottle neck to scalability. A smart container must try
very hard to avoid having threads wayting for the log. You should
probably need a queue of logging messages and a logger thread that takes
the care of it. 

The problem may be worst if you have a distribute container and even
worst
if HTTPSessions can migrate between different VMs from request to
request.

Jeff Haynes wrote:
> 
> Over the past couple of years I've worked with a number of different
> servlet engines - IBM Websphere (webfear), Jrun, Jserv,
> Weblogic (great but mega $$$) and most recently Tomcat.  One of the
> things I've found about moving code between these various servers
> is the inconsistency in logging - some of them support System logging,
> and some don't.  The simple solution to this problem was to use a
> server-independent logging class that could be used anywhere.
> 
> I wrote a very simple singleton class that will allow me to
> log to a central file from any servlet (or any other Java code,
> including JSP pages). I use a few of these across different
> applications on my site in order to keep logs for each section
> of the site in one place.  For example, I have a separate Member
> log and Msgboard log for those respective application elements.
> I find using this simple class makes life a lot easier when it
> comes to debugging and monitoring applications, not to mention
> the savings in time & effort having a logging system that works
> anywhere.
> 
> The following is an example of the logging class I'm currently using
> with Tomcat.  This was a very quick hack meant to get logging up
> and running while I'm troubleshooting my application.  There are
> two issues I still have with this code:
> 
> 1)      The code uses the java.io.PrintStream(java.io.OutputStream)
>         constructor, which is giving me a deprecation warning
>         when I compile using IBM JDK 1.1.8.  It still works, but
>         I need to update the code.
> 2)      There is no facility to roll the log when you restart the
>         server.  This means any old logs will be blown away.  If
>         you want to keep old logs, I would suggest renaming the
>         old log first (like tomcatlog.1) in the init method before
>         opening up the file for logging.  I plan on implementing
>         this when I get around to it.
> 
> If anyone works on these issues, could you please post the code
> back to the list?
> 
> This should be enough to get you going.  Hope it helps.
> 
> Jeff
> 
> --
> 
> To use this class:
> 
> - compile and put it in your classpath (I am master of the obvious)
> - make sure Tomcat has write permissions to your log file (unless you're
>   running it as root, which is not advised in a production environment)
> - Add the following code snippet anywhere you need it (make sure you
>   import CustomLog into any class using it):
> 
>         CustomLog log = CustomLog.instance();
>         log.println("Logging to the custom log");
> 
> /*
>  *      CustomLog
>  *
>  *      Copyright 2000 Tone Network Inc.
>  *
>  *      Author:         Jeff Haynes <je...@techno.ca>
>  *      Written:        February 19, 2000
>  *      Version:        1.0
>  */
> 
> import java.io.*;
> import java.net.*;
> import java.util.*;
> 
> public class CustomLog {
> 
>         private static PrintStream log;
>         private static CustomLog _instance = null;
>          private static final String logFileString = "/var/log/tomcat.log";
> 
>         /*
>          * Construct the only CustomLog object.
>          */
>         private CustomLog()
>         {
>                 init();
>         }
> 
> 
>         /*
>          * Initializes the singleton by opening the log file for
>          * printing to it.
>          */
>         private void init()
>         {
>                  Date now = new java.util.Date();
> 
>                 try
>                 {
>                         log = new PrintStream(new
> FileOutputStream(logFileString));
>                         log.println(now.toString() + " Starting custom
> logging.");
>                         System.out.println(now.toString()
>                                 + " Opened up custom log: " + logFileString);
>                 }
>                 catch (IOException e)
>                 {
>                         System.out.println("Can't open custom log: "
>                                 + logFileString);
>                 }
>         }
> 
>        /**
>          * Returns the instance of this class.
>          */
>         public static CustomLog instance ()
>         {
>                 if (_instance == null)
>                         _instance = new CustomLog();
>                 return _instance;
>         }
> 
> 
>         /*
>          * Prints the passed string to the log file.
>          *
>          * @param s     string to print in the log
>          */
>         public static void println(String s)
>         {
>                 log.println(s);
>         }
> 
> }
> 
> At 03:24 PM 2/25/00 +0530, you wrote:
> >Hi all,
> >
> >    I'm using Tomcat 3.0 with Apache 1.3.9(jdk1.2.2). My question is it
> >possible to log errors that occurs in servlets  and JSPs to Apache's error
> >log file?
> >
> >Thanks,
> >Sudheer.
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: general-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: general-help@jakarta.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: general-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: general-help@jakarta.apache.org

RE: Is it possible to log errors to server's log file in Tomcat 3.0?

Posted by caius van nouhuys <ca...@respondtv.com>.
I've written similar stuff, but I've also written an kludge to deal with
writing to the server's logs when I really needed to do that. I wrote a
class that makes a request to the server using HttpURLConnection, and the
server, obviously, will log that.

$#@---$#@@#$---$#@@#$---$#@@#$---@#$
Caius van Nouhuys
RespondTV -- 415 522 5260 x 207

Re: Is it possible to log errors to server's log file in Tomcat 3.0?

Posted by Jeff Haynes <Je...@techno.ca>.
Over the past couple of years I've worked with a number of different
servlet engines - IBM Websphere (webfear), Jrun, Jserv,
Weblogic (great but mega $$$) and most recently Tomcat.  One of the
things I've found about moving code between these various servers
is the inconsistency in logging - some of them support System logging, 
and some don't.  The simple solution to this problem was to use a 
server-independent logging class that could be used anywhere. 

I wrote a very simple singleton class that will allow me to 
log to a central file from any servlet (or any other Java code,
including JSP pages). I use a few of these across different 
applications on my site in order to keep logs for each section 
of the site in one place.  For example, I have a separate Member 
log and Msgboard log for those respective application elements.  
I find using this simple class makes life a lot easier when it 
comes to debugging and monitoring applications, not to mention 
the savings in time & effort having a logging system that works 
anywhere.

The following is an example of the logging class I'm currently using
with Tomcat.  This was a very quick hack meant to get logging up
and running while I'm troubleshooting my application.  There are
two issues I still have with this code:

1)	The code uses the java.io.PrintStream(java.io.OutputStream)
	constructor, which is giving me a deprecation warning
	when I compile using IBM JDK 1.1.8.  It still works, but 
	I need to update the code.
2)	There is no facility to roll the log when you restart the
	server.  This means any old logs will be blown away.  If
	you want to keep old logs, I would suggest renaming the
	old log first (like tomcatlog.1) in the init method before
	opening up the file for logging.  I plan on implementing 
	this when I get around to it.

If anyone works on these issues, could you please post the code
back to the list?  

This should be enough to get you going.  Hope it helps.


Jeff


--

To use this class:

- compile and put it in your classpath (I am master of the obvious)
- make sure Tomcat has write permissions to your log file (unless you're
  running it as root, which is not advised in a production environment)
- Add the following code snippet anywhere you need it (make sure you
  import CustomLog into any class using it):

	CustomLog log = CustomLog.instance();
	log.println("Logging to the custom log");






/*
 *      CustomLog
 *
 *      Copyright 2000 Tone Network Inc.
 *
 *      Author:         Jeff Haynes <je...@techno.ca>
 *      Written:        February 19, 2000
 *      Version:        1.0
 */
         
import java.io.*;
import java.net.*;
import java.util.*;
         
public class CustomLog {

        private static PrintStream log;
        private static CustomLog _instance = null;
	 private static final String logFileString = "/var/log/tomcat.log";

        /*
         * Construct the only CustomLog object.
         */
        private CustomLog()
        {
                init();
        }
                
                 
        /*
         * Initializes the singleton by opening the log file for
         * printing to it.
         */
        private void init()
        {
	         Date now = new java.util.Date();

                try
                {
                        log = new PrintStream(new
FileOutputStream(logFileString));
                        log.println(now.toString() + " Starting custom
logging.");
                        System.out.println(now.toString()
                                + " Opened up custom log: " + logFileString);
                }
                catch (IOException e)
                {
                        System.out.println("Can't open custom log: "
                                + logFileString);
                }
        }  

       /**
         * Returns the instance of this class.
         */
        public static CustomLog instance ()   
        {
                if (_instance == null)
                        _instance = new CustomLog();
                return _instance;
        }
                        
                                
        /*
         * Prints the passed string to the log file.
         *
         * @param s     string to print in the log
         */
        public static void println(String s)
        {  
                log.println(s);
        }

}




At 03:24 PM 2/25/00 +0530, you wrote:
>Hi all,
>
>    I'm using Tomcat 3.0 with Apache 1.3.9(jdk1.2.2). My question is it
>possible to log errors that occurs in servlets  and JSPs to Apache's error
>log file?
>
>Thanks,
>Sudheer.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: general-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: general-help@jakarta.apache.org
>
>