• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tomcat 5.5 and context.log

 
Ranch Hand
Posts: 590
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:


 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sean Keane
Ranch Hand
Posts: 590
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 590
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic