?
Solved

Tomcat 4: using Catalina logger

Posted on 2003-03-28
12
Medium Priority
?
724 Views
Last Modified: 2013-11-24
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.catalina.logger.FileLogger"        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:default]: Loading container servlet default2003-03-26 15:06:30 StandardWrapper[/demo31:invoker]: Loading container servlet invoker2003-03-26 15:07:59 StandardWrapperValve[F13TierServlet]: Servlet.service() for servlet F13TierServlet threw exceptionjavax.servlet.ServletException: Servlet execution threw an exception     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java: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.
0
Comment
Question by:zerg2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 1

Expert Comment

by:victorli
ID: 8230266
From my understanding, Tomcat has 2 log levels.

(1) Tomcat system logs level is handled by class "org.apache.catalina.logger.FileLogger" and logs goto the file you configured above.

(2) You application log messages are handled by class "org.apache.catalina.logger.SystemOutLogger" and
"org.apache.catalina.logger.SystemErrLogger". The default log file is "catalina.out" which is located at "../jarktaTomcat/logs/" directory. So if you use "System.err" or "System.out" print your log messages, you will see them in "catalina.out" file.

So please check your "catalina.out" file. This is where you look at your applicaiton logs.
0
 

Author Comment

by:zerg2000
ID: 8235798
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.
0
 
LVL 1

Expert Comment

by:victorli
ID: 8236027
// 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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:zerg2000
ID: 8236631
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.
0
 
LVL 1

Accepted Solution

by:
victorli earned 60 total points
ID: 8237641
Where did you run your java bean class?

You need to test and run them inside Tomcat instead of command line or IDE. Please note your servlet, bean class or any help classes for your web application will be eventually run in Tomcat container. I donot understand how can you see a console.

Let me explain this completely in an example. After you install Tomcat 4.1.24. In "server.xml", you will see the "examples" context and the "Logger" tag below, you can change the "Logger" tags like what you did with your "demo10". BUT the debug info will not go to this log file no mater you change or not change it.

Now do not change anything in the "server.xml". Goto the directory "jakarta-tomcat-4.1.24/webapps/examples/WEB-INF/classes" directory, you will find a java source file named "HelloWorldExample.java". Open this file, find a line called "PrintWriter out= responser.getWriter()". Then add the following code under this "PrintWriter .." line:

System.out.println("**** System.out****");
System.err.println("**** System.err****");

Save this file and compile it in where it was:
javac -classpath .../.../servlet.jar HelloWorldExample.java

Start your tomcat server, in your browser use:
http://localhost:8080/examples/servlet/HelloWorldExample
to access this servlet.

Then goto "../jakarta-tomcat-4.1.24/logs" directory to check your "catalina.out" file, you will see the
"**** System.out****"   and
"**** System.err****"

I put the "System.out" in servlet class, but if you put them in bean class will have the same result.
 
0
 

Author Comment

by:zerg2000
ID: 8242327
Hi vitorli,

Thanks for your effort. I will try to digest what you said.

Here is your dollars.

Thanks
0
 

Author Comment

by:zerg2000
ID: 8242395
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
0
 

Author Comment

by:zerg2000
ID: 8242550
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
0
 
LVL 1

Expert Comment

by:victorli
ID: 8243251
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.catalina.logger.SystemOutLogger ... to somewhere.

Let me figure it out...



0
 
LVL 1

Expert Comment

by:victorli
ID: 8243652
I repost this question in JSP area, the link is :

http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_20569688.html
0
 

Author Comment

by:zerg2000
ID: 8243674
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.catalina.logger.SystemOutLogger"
                     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:default]: Loading container servlet default
StandardWrapper[/demo:invoker]: Loading container servlet invoker
0
 

Expert Comment

by:mbm63
ID: 8699284
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.GenericServlet.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.


0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question