aspose file tools*
The moose likes Servlets and the fly likes Logging info on server side Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Logging info on server side" Watch "Logging info on server side" New topic
Author

Logging info on server side

Fabio Piergentili
Ranch Hand

Joined: Sep 04, 2009
Posts: 57
Does any one know how I can log to the tomcat server logs via a class not extending HTTPServlet on the server side. Basically a class used by a servlet. In the servlet I simply use log(" mesg"). How can I pass this ability to another class?

Thanks
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Why would you want to log something that has already been logged ?


JDBCSupport - An easy to use, light-weight JDBC framework -
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60975
    
  65

Use Log4J.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

There are many logging frameworks out there that can do it for you. Have a look at log4j like Bear suggested


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Fabio Piergentili
Ranch Hand

Joined: Sep 04, 2009
Posts: 57
log4j worked great. For anyone else interested, this is all I had to do:

1. put log4j jar file in lib directory of tomcat
2. provide a log4j.properties file located in the tomcat lib directory to set up logging to a file instead of console ( I have no idea where the console stuff would go as this is getting run from the tomcat container )
3. in the class provide ( In my case the class is QueryBuilder )

Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Fabio Piergentili wrote:2. provide a log4j.properties file located in the tomcat lib directory to set up logging to a file instead of console ( I have no idea where the console stuff would go as this is getting run from the tomcat container )
[/code]


The console is the window in which the user launched the server. If you're running as a system service, then I think you don't have a console (at least on Windows).

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60975
    
  65

That's a Windows-only situation. On other OS's, console is the catalina.out file in the logs folder.
Fabio Piergentili
Ranch Hand

Joined: Sep 04, 2009
Posts: 57
You are correct. Now I do not have to track another file. I just log to console and it dumps into catalina.out file in the tomcat logs directory.

Thanks for the info.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Logging info on server side