RE: Logging from a servlet in Tomcat
I haven't tried this in 4 but in 3 you can always just print to stdout or stderr eg. System.out.println(In the Foo function); Which will get printed to the console or your logs depending on how you're running tomcat -Original Message- From: Dr. Evil [mailto:[EMAIL PROTECTED]] Sent: Friday, October 19, 2001 10:30 AM To: [EMAIL PROTECTED] Subject: Logging from a servlet in Tomcat I have a question: It would be extremely useful for a servlet to be able to record debugging messages in some way. I don't have a Java debugger, but I could do a lot of debugging if I had a command that looked like this: log(We are in this part of the code now); I have seen documentation for a command like that, and I have tried it in my installation of Tomcat 4.0, but it doesn't send any output anywhere, so it seems useless. Is there a way to get it to work? Thanks
RE: Logging from a servlet in Tomcat
Best is to use Log4j for logging. It gives more control and flexibility than using the servlet logging facility. -Original Message- From: Barney Hamish [mailto:[EMAIL PROTECTED]] Sent: Friday, October 19, 2001 10:42 AM To: '[EMAIL PROTECTED]' Subject: RE: Logging from a servlet in Tomcat I haven't tried this in 4 but in 3 you can always just print to stdout or stderr eg. System.out.println(In the Foo function); Which will get printed to the console or your logs depending on how you're running tomcat -Original Message- From: Dr. Evil [mailto:[EMAIL PROTECTED]] Sent: Friday, October 19, 2001 10:30 AM To: [EMAIL PROTECTED] Subject: Logging from a servlet in Tomcat I have a question: It would be extremely useful for a servlet to be able to record debugging messages in some way. I don't have a Java debugger, but I could do a lot of debugging if I had a command that looked like this: log(We are in this part of the code now); I have seen documentation for a command like that, and I have tried it in my installation of Tomcat 4.0, but it doesn't send any output anywhere, so it seems useless. Is there a way to get it to work? Thanks
Re: Logging from a servlet in Tomcat
I haven't tried this in 4 but in 3 you can always just print to stdout or stderr eg. System.out.println(In the Foo function); Which will get printed to the console or your logs depending on how you're running tomcat That is a very good idea. I'll give that a try. Also, I found that the log() command does work; I think there was a permissions problem on the logs/ directory. Thanks
RE: Logging from a servlet in Tomcat
One question about this subject. Why the Tomcat (4) team (Craig and others) didn't use log4J to trace the server ? -Message d'origine- De: G.Nagarajan [SMTP:[EMAIL PROTECTED]] Date: vendredi 19 octobre 2001 10:48 À:[EMAIL PROTECTED] Objet:RE: Logging from a servlet in Tomcat Best is to use Log4j for logging. It gives more control and flexibility than using the servlet logging facility. -Original Message- From: Barney Hamish [mailto:[EMAIL PROTECTED]] Sent: Friday, October 19, 2001 10:42 AM To: '[EMAIL PROTECTED]' Subject: RE: Logging from a servlet in Tomcat I haven't tried this in 4 but in 3 you can always just print to stdout or stderr eg. System.out.println(In the Foo function); Which will get printed to the console or your logs depending on how you're running tomcat -Original Message- From: Dr. Evil [mailto:[EMAIL PROTECTED]] Sent: Friday, October 19, 2001 10:30 AM To: [EMAIL PROTECTED] Subject: Logging from a servlet in Tomcat I have a question: It would be extremely useful for a servlet to be able to record debugging messages in some way. I don't have a Java debugger, but I could do a lot of debugging if I had a command that looked like this: log(We are in this part of the code now); I have seen documentation for a command like that, and I have tried it in my installation of Tomcat 4.0, but it doesn't send any output anywhere, so it seems useless. Is there a way to get it to work? Thanks
RE: Logging from a servlet in Tomcat
dont know. But logging has saved my skin many times. It is worth the effort to use log4j than putting lots of system.out.println statements. They become clumsy when you have some 10 servlets printing to the console... -Original Message- From: Arnaud Héritier [mailto:[EMAIL PROTECTED]] Sent: Friday, October 19, 2001 10:56 AM To: '[EMAIL PROTECTED]' Subject: RE: Logging from a servlet in Tomcat One question about this subject. Why the Tomcat (4) team (Craig and others) didn't use log4J to trace the server ? -Message d'origine- De: G.Nagarajan [SMTP:[EMAIL PROTECTED]] Date: vendredi 19 octobre 2001 10:48 À:[EMAIL PROTECTED] Objet:RE: Logging from a servlet in Tomcat Best is to use Log4j for logging. It gives more control and flexibility than using the servlet logging facility. -Original Message- From: Barney Hamish [mailto:[EMAIL PROTECTED]] Sent: Friday, October 19, 2001 10:42 AM To: '[EMAIL PROTECTED]' Subject: RE: Logging from a servlet in Tomcat I haven't tried this in 4 but in 3 you can always just print to stdout or stderr eg. System.out.println(In the Foo function); Which will get printed to the console or your logs depending on how you're running tomcat -Original Message- From: Dr. Evil [mailto:[EMAIL PROTECTED]] Sent: Friday, October 19, 2001 10:30 AM To: [EMAIL PROTECTED] Subject: Logging from a servlet in Tomcat I have a question: It would be extremely useful for a servlet to be able to record debugging messages in some way. I don't have a Java debugger, but I could do a lot of debugging if I had a command that looked like this: log(We are in this part of the code now); I have seen documentation for a command like that, and I have tried it in my installation of Tomcat 4.0, but it doesn't send any output anywhere, so it seems useless. Is there a way to get it to work? Thanks
Re: Logging from a servlet in Tomcat
I've joined this thread late, so apologies if I am stating the obvious. I thought this.getServletContextlog(java.lang.String message, java.lang.Throwable throwable) was what one must use. In case of Catalina (4.0.1) this output goes to whatever logger is specified in the server.xml, Logger className=org.apache.catalina.logger.FileLogger directory=logs prefix=myservlet_log. suffix=.txt timestamp=true/ (in fact by allowing the class name to be specified at run time, one can send it to an MQ queue etc etc). Again, apologies for stating the obvious. Cheers -raj dont know. But logging has saved my skin many times. It is worth the effort to use log4j than putting lots of system.out.println statements. They become clumsy when you have some 10 servlets printing to the console... -Original Message- From: Arnaud Héritier [mailto:[EMAIL PROTECTED]] Sent: Friday, October 19, 2001 10:56 AM To: '[EMAIL PROTECTED]' Subject: RE: Logging from a servlet in Tomcat One question about this subject. Why the Tomcat (4) team (Craig and others) didn't use log4J to trace the server ? -Message d'origine- De: G.Nagarajan [SMTP:[EMAIL PROTECTED]] Date: vendredi 19 octobre 2001 10:48 À:[EMAIL PROTECTED] Objet:RE: Logging from a servlet in Tomcat Best is to use Log4j for logging. It gives more control and flexibility than using the servlet logging facility. -Original Message- From: Barney Hamish [mailto:[EMAIL PROTECTED]] Sent: Friday, October 19, 2001 10:42 AM To: '[EMAIL PROTECTED]' Subject: RE: Logging from a servlet in Tomcat I haven't tried this in 4 but in 3 you can always just print to stdout or stderr eg. System.out.println(In the Foo function); Which will get printed to the console or your logs depending on how you're running tomcat -Original Message- From: Dr. Evil [mailto:[EMAIL PROTECTED]] Sent: Friday, October 19, 2001 10:30 AM To: [EMAIL PROTECTED] Subject: Logging from a servlet in Tomcat I have a question: It would be extremely useful for a servlet to be able to record debugging messages in some way. I don't have a Java debugger, but I could do a lot of debugging if I had a command that looked like this: log(We are in this part of the code now); I have seen documentation for a command like that, and I have tried it in my installation of Tomcat 4.0, but it doesn't send any output anywhere, so it seems useless. Is there a way to get it to work? Thanks
Re: Logging from a servlet in Tomcat
On 19 Oct 2001, Dr. Evil wrote: Date: 19 Oct 2001 08:29:44 - From: Dr. Evil [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Logging from a servlet in Tomcat I have a question: It would be extremely useful for a servlet to be able to record debugging messages in some way. I don't have a Java debugger, but I could do a lot of debugging if I had a command that looked like this: log(We are in this part of the code now); I have seen documentation for a command like that, and I have tried it in my installation of Tomcat 4.0, but it doesn't send any output anywhere, so it seems useless. Is there a way to get it to work? By default, log output from your servlets goes to a file in the logs directory. You can change where it goes by setting up a Logger element to do what you want. Configuration information is included in Tomcat's download, or available online at: http://jakarta.apache.org/tomcat/tomcat-4.0-doc/config/logger.html Thanks Craig
RE: Logging from a servlet in Tomcat
On Fri, 19 Oct 2001, Arnaud Héritier wrote: Date: Fri, 19 Oct 2001 10:55:49 +0200 From: Arnaud Héritier [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED], [EMAIL PROTECTED] [EMAIL PROTECTED] To: '[EMAIL PROTECTED]' [EMAIL PROTECTED] Subject: RE: Logging from a servlet in Tomcat One question about this subject. Why the Tomcat (4) team (Craig and others) didn't use log4J to trace the server ? Using Log4J for Tomcat internally is on the TODO list, but has never been high enough on anyone's priority list to get around to. Of course, there is absolutely nothing that stops webapps from using Log4J for themselves. For Tomcat 4 to use Log4J itself, there would be two possible implementation approaches: * (Easy) - Write a Logger implementation that writes to Log4J underneath. This would be pretty trivial, but wouldn't really give the fine-grained control over what output actually gets written that is the reason to use Log4J in the first place. * (Harder) - Rip out all the Logger stuff and replace it with corresponding Log4J calls. Besides breaking backwards compatibility, there are a couple of gotchas with this approach: - Log4J's category model does not really match very well with Tomcat 4's internal architecture of components, and in particular the ability to inherit a parent's Logger. Ceki Gulcu (author of Log4J) has suggested a couple of approaches, but they aren't as elegant as I would prefer. - There is an amount-of-typing hit (sorry, gotta be a little selfish once in a while :-) and a potential performance hit for doing this switch. Tomcat's internal code has lots of this kind of thing: if (debug = 2) logger.log(Started the + name + application); where you use String concatenation to build the message. Because of the way Java works, the string concatenation will *only* be done if debug is actually = 2, so you don't pay the performance cost unless you're actually going to do the logging. The typical Log4J pattern for this would be something like: category.debug(Started the + name + application); which would let the logger implementation decide whether or not to actually do the output, based on your Log4J configuration settings. However, you pay the cost of doing the string concatination no matter what - and that's a waste of effort if you aren't actually going to write the message out. The better solution is something like (forgive me if I don't get the syntax exactly right -- I don't have the APIs in front of me): if (category.isDebugEnabled()) category.debug(Started the + name + application); which is much wordier, and sort of redundant. And you don't have the conditional checks for all the possible levels (or at least you didn't use to - this might have changed), so you might not be able to apply this optimization even if you're willing to type all the extra characters. Craig