zerg2000
asked on
Tomcat 4: using Catalina logger
Hi,
I am using Tomcat 4.1 and I am able to set my servlet processing log message to catalina log file
<Context path="/demo10" docBase="D:\demo10" debug="0"><Logger className="org.apache.cata lina.logge r.FileLogg er" prefix="demo10" suffix=".txt" timestamp="true"/> </Context>
My log file output:
2003-03-26 15:06:30 StandardManager[/demo31]: Seeding of random number generator has been completed2003-03-26 15:06:30 StandardWrapper[/demo31:de fault]: Loading container servlet default2003-03-26 15:06:30 StandardWrapper[/demo31:in voker]: Loading container servlet invoker2003-03-26 15:07:59 StandardWrapperValve[F13Ti erServlet] : Servlet.service() for servlet F13TierServlet threw exceptionjavax.servlet.Ser vletExcept ion: Servlet execution threw an exception at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:269 ) at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:1 93) at org.apache.catalina.core.S tandardWra pperValve. invoke(Sta ndardWrapp erValve.ja va:260)
My Question:
How do I output my application debug message to the same catalina log file. For example, instead of using System.out.println("vvv") to command console, I would like to send the message to the above log file.
Please teach me. Thank you.
I am using Tomcat 4.1 and I am able to set my servlet processing log message to catalina log file
<Context path="/demo10" docBase="D:\demo10" debug="0"><Logger className="org.apache.cata
My log file output:
2003-03-26 15:06:30 StandardManager[/demo31]: Seeding of random number generator has been completed2003-03-26 15:06:30 StandardWrapper[/demo31:de
My Question:
How do I output my application debug message to the same catalina log file. For example, instead of using System.out.println("vvv") to command console, I would like to send the message to the above log file.
Please teach me. Thank you.
ASKER
Hi Victorli,
Thank you for your advice.
However, I am not sure how to proceed after your reading your instruction.
Let's say I have a Java Bean class in my server side, how do I the initialization of the catalina logger in order to redirect my System.out.println() to the log file?
// what to import?
public class test
{
public test()
{
// what to do??
}
}
Thank you very much.
Thank you for your advice.
However, I am not sure how to proceed after your reading your instruction.
Let's say I have a Java Bean class in my server side, how do I the initialization of the catalina logger in order to redirect my System.out.println() to the log file?
// what to import?
public class test
{
public test()
{
// what to do??
}
}
Thank you very much.
// need not do any import.
public class test
{
public test()
{
try {
...
} catch (Exception ex) {
System.out.println("my error message"+ex.getMessage()); etc...
//or use System.err.println("...")
}
}
}
Then your applicaiton error message will be stored in the default file "catalina.out". I check this file regularly in my company's website. It is very useful.
In my case, I did not configure any log setting in the "server.xml". I am not sure if you can configure Tomcat to let it output application messages to another file instead of "catalina.out". I donot think it is necessary.
Using "System.out" or "System.err" to print debug information is not that good. One of Java 1.4's new features is "Logger" class. Use this class may be better.
public class test
{
public test()
{
try {
...
} catch (Exception ex) {
System.out.println("my error message"+ex.getMessage());
//or use System.err.println("...")
}
}
}
Then your applicaiton error message will be stored in the default file "catalina.out". I check this file regularly in my company's website. It is very useful.
In my case, I did not configure any log setting in the "server.xml". I am not sure if you can configure Tomcat to let it output application messages to another file instead of "catalina.out". I donot think it is necessary.
Using "System.out" or "System.err" to print debug information is not that good. One of Java 1.4's new features is "Logger" class. Use this class may be better.
ASKER
Hi Victorli,
Thank you for your help.
But we have some misunderstanding. Currently, my System.out.println() will print the message to console, not catalina.out default file.
So, my question is, how to make my System.out.println() to output catalina.out default file, like what happen in your system.
Thanks again.
Thank you for your help.
But we have some misunderstanding. Currently, my System.out.println() will print the message to console, not catalina.out default file.
So, my question is, how to make my System.out.println() to output catalina.out default file, like what happen in your system.
Thanks again.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi vitorli,
Thanks for your effort. I will try to digest what you said.
Here is your dollars.
Thanks
Thanks for your effort. I will try to digest what you said.
Here is your dollars.
Thanks
ASKER
Hi victorli,
!!You need to test and run them inside Tomcat instead of command line or IDE!!
I think the problem is from here. What do you mean by the above statement? I started my Tomcat by double-clicking the startup.bat from my Windows Explorer. In this way, a command console will be brought up and all the messages from System.out.println() will appear on the Command console.
Please help me. Thanks
!!You need to test and run them inside Tomcat instead of command line or IDE!!
I think the problem is from here. What do you mean by the above statement? I started my Tomcat by double-clicking the startup.bat from my Windows Explorer. In this way, a command console will be brought up and all the messages from System.out.println() will appear on the Command console.
Please help me. Thanks
ASKER
Hi victorli,
!!You need to test and run them inside Tomcat instead of command line or IDE!!
I think the problem is from here. What do you mean by the above statement? I started my Tomcat by double-clicking the startup.bat from my Windows Explorer. In this way, a command console will be brought up and all the messages from System.out.println() will appear on the Command console.
Please help me. Thanks
!!You need to test and run them inside Tomcat instead of command line or IDE!!
I think the problem is from here. What do you mean by the above statement? I started my Tomcat by double-clicking the startup.bat from my Windows Explorer. In this way, a command console will be brought up and all the messages from System.out.println() will appear on the Command console.
Please help me. Thanks
Ooooops! I forget about your Tomcat is running in Windows. Very sorry about that.
You should not accept my answer at this stage.
Anyway, I just checked the Windows edition of Tomcat4.1.24 and found "catalina.out" does not exist(in Linux it is always there). Maybe we need to confugure the "server.xml" and put the "<Logger ClassName="org.apache.cata lina.logge r.SystemOu tLogger ... to somewhere.
Let me figure it out...
You should not accept my answer at this stage.
Anyway, I just checked the Windows edition of Tomcat4.1.24 and found "catalina.out" does not exist(in Linux it is always there). Maybe we need to confugure the "server.xml" and put the "<Logger ClassName="org.apache.cata
Let me figure it out...
I repost this question in JSP area, the link is :
https://www.experts-exchange.com/questions/20569688/Tomcat-4-1-24-configuration-on-windows.html
https://www.experts-exchange.com/questions/20569688/Tomcat-4-1-24-configuration-on-windows.html
ASKER
Thanks alot victorli,
I tried your method. Below is part of my server.xml:
<Context path="/demo" docBase="D:\demo" debug="0">
<Logger className="org.apache.cata lina.logge r.SystemOu tLogger"
prefix="demo" suffix=".txt" timestamp="true"/>
</Context>
More output to the console this time. And System.out.println is output to the console also. My demo log file still only contains servelt engine log message, not my application message. Please help.
WebappLoader[/demo]: Deploying class repositories to work directory D:\Tomcat\
work\Standalone\localhost\ demo
WebappLoader[/demo]: Deploy class files /WEB-INF/classes to D:\demo\WEB-INF\classes
StandardManager[/demo]: Seeding random number generator class java.security.Se
cureRandom
StandardManager[/demo]: Seeding of random number generator has been completed
StandardWrapper[/demo:defa ult]: Loading container servlet default
StandardWrapper[/demo:invo ker]: Loading container servlet invoker
I tried your method. Below is part of my server.xml:
<Context path="/demo" docBase="D:\demo" debug="0">
<Logger className="org.apache.cata
prefix="demo" suffix=".txt" timestamp="true"/>
</Context>
More output to the console this time. And System.out.println is output to the console also. My demo log file still only contains servelt engine log message, not my application message. Please help.
WebappLoader[/demo]: Deploying class repositories to work directory D:\Tomcat\
work\Standalone\localhost\
WebappLoader[/demo]: Deploy class files /WEB-INF/classes to D:\demo\WEB-INF\classes
StandardManager[/demo]: Seeding random number generator class java.security.Se
cureRandom
StandardManager[/demo]: Seeding of random number generator has been completed
StandardWrapper[/demo:defa
StandardWrapper[/demo:invo
Hi zerg2000,
I don't know if you're still watching this topic, however
if you need to print messages to the log file you just need to use the
javax.servlet.GenericServl et.log( String ) method!!!
This method writes the specified message to a servlet log file, usually an event log. The name and type of the servlet log file is specific to the servlet container (in the server.xml file if you're using Tomcat).
Hope this can help you.
I don't know if you're still watching this topic, however
if you need to print messages to the log file you just need to use the
javax.servlet.GenericServl
This method writes the specified message to a servlet log file, usually an event log. The name and type of the servlet log file is specific to the servlet container (in the server.xml file if you're using Tomcat).
Hope this can help you.
(1) Tomcat system logs level is handled by class "org.apache.catalina.logge
(2) You application log messages are handled by class "org.apache.catalina.logge
"org.apache.catalina.logge
So please check your "catalina.out" file. This is where you look at your applicaiton logs.