This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Logging in Tomcat 5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Logging in Tomcat 5" Watch "Logging in Tomcat 5" New topic
Author

Logging in Tomcat 5

sushi sri
Ranch Hand

Joined: Oct 27, 2009
Posts: 38
Hi,

I'm working on Linux machine. hope this doesn't matter for this topic.

I've set up log4j in Tomcat 5.0.28 by copying the commons-jar & log4j.jar in commons lib folder and log4j.properties in common/classes folder.


With this i was able to send my logs to the file specified in the log4j.properties.

I want to know how can we implement the following things.

1. Want to separate only the stdout& errors from the log file to another, as of ow i'm getting messages of commongs logging and server stuff etc..etc...

2. How to do set up the loggin specific to myapplication. Not to the entire tomcat applications.
So that when i provide the .war file, logging jars and properties file also can be supplied to deploy along with the war.

Any help for this is appreciated.
Thank you very much in advance.



Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16158
    
  21

uranch sushi wrote:Hi,

I'm working on Linux machine. hope this doesn't matter for this topic.

I've set up log4j in Tomcat 5.0.28 by copying the commons-jar & log4j.jar in commons lib folder and log4j.properties in common/classes folder.


With this i was able to send my logs to the file specified in the log4j.properties.

I want to know how can we implement the following things.

1. Want to separate only the stdout& errors from the log file to another, as of ow i'm getting messages of commongs logging and server stuff etc..etc...

2. How to do set up the loggin specific to myapplication. Not to the entire tomcat applications.
So that when i provide the .war file, logging jars and properties file also can be supplied to deploy along with the war.

Any help for this is appreciated.
Thank you very much in advance.





stdout and stderr aren't logfiles and you should NEVER use them in production apps. On Linux, they get squashed together and dumped to catalina.out, but they lack the amenities of true logfiles.

To configure log4j for a webapp, set up a log4j config file (properties or XML, as you like). This file goes into the WEB-INF/classes directory. If you want to do fixed configurations, hardcoding your logfile names and stuff, that's all you need. If you want to be able to override the configuration, you can create a small "null servlet" (just init(), no doGet()/doPost()) and programmatically configure log4j like the examples on the Log4 website show, placing the code in the null servlet's init() method. If you're REALLY ambitious, that code can pluck config out of the webapp context configuration using JNDI.

Complex projects often have multiple logging systems used by the different subsystems, so you might need to add a logging consolidator to ensure that they all get rerouted to log4J.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Logging in Tomcat 5