Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logging info on server side

 
Fabio Piergentili
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you want to log something that has already been logged ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use Log4J.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many logging frameworks out there that can do it for you. Have a look at log4j like Bear suggested
 
Fabio Piergentili
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a Windows-only situation. On other OS's, console is the catalina.out file in the logs folder.
 
Fabio Piergentili
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic