Redirecting Tomcat console output into a textfile

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nirmala123
    New Member
    • Jul 2007
    • 10

    Redirecting Tomcat console output into a textfile

    Hai everybody,

    how can i redirect tomcat console output into a text file.

    I want to print all the error output into the textfile.Help me,

    thanks in advance......
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Originally posted by Nirmala123
    Hai everybody,

    how can i redirect tomcat console output into a text file.

    I want to print all the error output into the textfile.Help me,

    thanks in advance......
    What operating system are you running Tomcat on?

    Comment

    • Nirmala123
      New Member
      • Jul 2007
      • 10

      #3
      Originally posted by Motoma
      What operating system are you running Tomcat on?
      Thank you for your reply.

      We are using windows xp operating system.

      Thanks in advance...

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by Nirmala123
        Thank you for your reply.

        We are using windows xp operating system.

        Thanks in advance...
        Is there a log directory in your Tomcat install directory?

        Comment

        • Nirmala123
          New Member
          • Jul 2007
          • 10

          #5
          Originally posted by Motoma
          Is there a log directory in your Tomcat install directory?

          logs directory is there in the tomcat directory.

          Thanks in advance.

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            Originally posted by Nirmala123
            logs directory is there in the tomcat directory.

            Thanks in advance.
            And error output is not being placed in that directory?

            Comment

            • Nirmala123
              New Member
              • Jul 2007
              • 10

              #7
              I'm asking tht whatever we print in console output using System.out.prin tln should also be stored in a log file for future verification. How can we do that?
              Do we have to apply some codings or we have change the settings in the xml file.
              Pls provide me answers. It would be so helpful.

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #8
                Why not create a function that both writes output to a file and to stdout?

                Comment

                • Nirmala123
                  New Member
                  • Jul 2007
                  • 10

                  #9
                  Originally posted by Motoma
                  Why not create a function that both writes output to a file and to stdout?
                  Thats why i am asking....

                  Give me some codings for do that

                  This is very helpful for me...

                  Comment

                  • Motoma
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3236

                    #10
                    I'm going to move this thread to the Java Forum, because the experts there will be able to help you better than I.

                    Comment

                    • itsraghz
                      New Member
                      • Mar 2007
                      • 124

                      #11
                      Is it resolved?


                      If not, How big is your application? I think you need to do a work around for making the SOPs printed into a log file rather than or along with the console output.

                      Comment

                      • Nirmala123
                        New Member
                        • Jul 2007
                        • 10

                        #12
                        Originally posted by itsraghz
                        Is it resolved?



                        If not, How big is your application? I think you need to do a work around for making the SOPs printed into a log file rather than or along with the console output.

                        Thanks for your reply.

                        No.I don't know the answer.

                        I want to print all the error messages and System.out.prin t messages in the text file.

                        Whatever print in the tomcat server , I want to get in that text file.

                        Thanks in Advance....

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #13
                          Originally posted by Nirmala123
                          Thanks for your reply.

                          No.I don't know the answer.

                          I want to print all the error messages and System.out.prin t messages in the text file.

                          Whatever print in the tomcat server , I want to get in that text file.

                          Thanks in Advance....
                          This article explains how to write to files, however, I suggest you also take a look at the Logger.

                          Comment

                          • itsraghz
                            New Member
                            • Mar 2007
                            • 124

                            #14
                            Originally posted by Nirmala123
                            Thanks for your reply.

                            No.I don't know the answer.

                            I want to print all the error messages and System.out.prin t messages in the text file.

                            Whatever print in the tomcat server , I want to get in that text file.

                            Thanks in Advance....
                            Thats fine. As the admin pointed out, you may please read the articles about how to read and write into a file and about the Java Logging API.

                            You need to understand one thing that whatever you print using SOP (System.out.pri ntln or System.err.prin tln) they will ONLY get printed on console (screen).

                            If at all you want to divert or delegate the output to some other file (you may call it as a log file or text file), you have to manually replace all the SOPs with a method call which would in turn write it into a log file.

                            After going through the Java Logging API, what you can do is,

                            (i) write one class with a method for logging (as per the Logging API) with the specific properties being set (filename etc).

                            (ii) Manually invoke this method appropriately (if its static call with the classname; if not call with its instance) everywhere you have the System.out.prin tln or System.err.prin tln statements in your application.


                            If you want the output lines printed on the Console with respect to the status of Tomcat (say during its startup), you dont need to worry. Because, all information are by default getting stored into a log file with the "machine name & date and time at which it was running" (for example, "localhost_log.2 007-06-26" for the information logged while running on localhost (same machine) at 26th June 2007)).

                            The log file would be stored in a directory called "logs" which would be present under your TOMCAT_ROOT directory where you have installed Tomcat.

                            Hope this helps!

                            Comment

                            Working...