aspose file tools*
The moose likes Tomcat and the fly likes Tomcat 5.5 and context.log Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat 5.5 and context.log" Watch "Tomcat 5.5 and context.log" New topic
Author

Tomcat 5.5 and context.log

Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Hi guys,

I have a simple filter that is outputing a message to a log file. I am following an example from a book. It said I should expect to see the log message in a log file. However I only see the message in the console for Tomcat, not the log file. Any ideas why?

I had a look at the documentation for Tomcat. The logging section http://tomcat.apache.org/tomcat-5.5-doc/logging.html doesn't mention anything about where the logs for ServletContext.log go? The JavaDoc for the Servlet API just says that the log method should output to a log file.

Any ideas?


Cheers,

Sean.



Here is my example:



SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

The servletcontext log is written to wherever the container (Tomcat) wants it written. For Tomcat, that means stdout, which usually means the catalina.out file.

By and large, I wouldn't use this built-in logger anymore. It doesn't have the benefits of a "true" logger such as the ability to filter, route, stamp, or replicate log messages. I use log4j mostly.


Customer surveys are for companies who didn't pay proper attention to begin with.
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Ok, I see the logs getting output to stdout. But I don't understand what you mean by catalina.out file? Did you mean that Tomcat outputs ServletContext logs to a file called catalina.out? I searched my Tomcat installation for this file and it does not exist. I'm using Tomcat 5.5.

Where would I find official Tomcat documentation of how it handles ServletContext.log? I already search the documentation for Tomcat 5.5 and found no mention. (Just wondering how I would have figured out myself how Tomcat handles these logs).
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

I'd seriously consider migrating to Tomcat6 or 7 if at all possible. However, that wouldn't change how the logging works.

If there's official documentation on Tomcat's handling of servercontext logs, I haven't noticed it, although having said that, there is a (cryptic) section of the Tomcat docs that cover replacing the default juli system with alternatives such as log4j. It's almost never worth doing that, however, as that requires you to build a custom Tomcat from source.

The logs/catalina.out destination is set via a shell stdio redirect of the JVM's stdout and stderr in the catalina.sh and catalina.bat files.
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Yep, I intend moving to Tomcat 6 or 7 at a later stage. It's just that I'm working through a book at the moment which used Tomcat 5 - so I'm using it to ensure all the examples work smoothly.

I searched all the files in my Tomcat installation for references to "catalina.out". The only place I found a reference was in catalina.sh. There is no reference in catalina.bat.

Since I am running on a Windows machine and there is no reference to "catalina.out" in catalina.bat, I'm guessing that I should not expect to see the logs to ServletContext.log outputted to any file - they will only go to stdout. Does this sound correct?

Is there any way for me to configure Tomcat 5 so that it outputs the logs to ServletContext.log to a log file?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

Hmmm. I know that in some cases, the Windows spin of Tomcat can produce a catalina.out, but you're right. It isn't handled in the stock catalina.bat. I don't usually run Tomcat under Windows, so I'm not always up on the finer points.

There are probably 2 reasons why catalina.bat doesn't route the logs. First, because typically, Tomcat is run as a Windows Service. Secondly, because Windows can do odd things when you invoke a command line app. For example, when you run the Tomcat startup.bat by double-clicking on it.

You can always route the console output for Tomcat yourself, however:

Or:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat 5.5 and context.log