9 Replies Latest reply: Sep 5, 2007 5:24 PM by 807600 RSS

    Writing system log into a separate file.

    807600
      Hey pals

      Yesterday I was talking to some body, and he was saying they write their application log into a separate file. I went in and checked what we did . All I found in most files related to connectivity was
      krs.fd.mdh.gls.Log.write(and the thing that has to be written)
      krs.fd.mdh.gls is the path name.
      So, I assume we are writing it to the Systemout log file right?
      So, what must the other person have written in thier application to write it to a different file which is at d:\weblogs\<application name>?
      How do we create a new file, and write to it?

      I'm willing to give ya 10 of my hard earned patented dukes to ya hihihi;)

      Message was edited by:
      Kishorei20
        • 1. Re: Writing system log into a separate file.
          807600
          krs.fd.mdh.gls.Log.write(String);
          // krs.fd.mdh.gls would be the package name,
          // Log would be the class
          // write would apparently be the static method in the class that does the write.
          // More than that I could only guess w/o seeing the code, but probably it
          // writes through a Reader Object to some designated logfile.
          • 2. Re: Writing system log into a separate file.
            807600
            This is my 'log' class. This is where the write class is defined.
            import java.io.OutputStreamWriter;
            import java.io.PrintWriter;
            import java.util.Date;
            
            public class Log 
            {
            private static PrintWriter out = null;
            //private static boolean logStatus = false; GPR TRACING - SWAP THIS!!
            private static boolean logStatus = true;
            static
            {
                 out = new PrintWriter(new OutputStreamWriter(System.out));
            }
            /**
             * Log constructor comment.
             */
            public Log() {
                 super();
            }
            public static void write(String who, String msg)
            {
                 if(logStatus)
                 {
                      String when = new Date() + ": ";
                      out.println(when + who + ": " + msg);
                      out.flush();
                 }
            }
            }
            • 3. Re: Writing system log into a separate file.
              807600
              It appears to say out.println and out. flush !!!!

              Is that where the web server knows that it has to send the data/ message to the log file?

              What do people add to this if they have to create a new page and all this is written into that page?
              • 4. Re: Writing system log into a separate file.
                807600
                Refer to my previous post ... In my hurry I wrote Reader, when I meant Writer. This obviously is the case; and write is not a class, but a method - I'm sure that was a typo on your part.

                I don't see why it would be particularly difficult to change, alter, extend, whatever (have) a Log class that writes to any number of "Files", rather than System.out. Of course you know that on the console or elsewheres System.out can be re-directed to a file, just as if you did:
                C:\mydir>dir *.log >listoflogs.txt
                • 5. Re: Writing system log into a separate file.
                  807600
                  Refer to my previous post ... In my hurry I wrote
                  Reader, when I meant Writer. This obviously is the
                  case; and write is not a class, but a method - I'm
                  sure that was a typo on your part.

                  I don't see why it would be particularly difficult to
                  change, alter, extend, whatever (have) a Log class
                  that writes to any number of "Files", rather than
                  System.out. Of course you know that on the console or
                  elsewheres System.out can be re-directed to a file,
                  just as if you did:
                  C:\mydir>dir *.log >listoflogs.txt
                  oops I think I am missing you.
                  I'm sorry (my dumb brain)
                  What I want is I don't want to write to the file it's already writing to. It's writing to the app server log file.
                  Instead, I want it to write to a new file which is not there now. We have to create a new file and then write into it.
                  Moreover, I don't want to change the code in DOS. I wantto imbibe that in the code. SO, that it is done for once and ever.
                  • 6. Re: Writing system log into a separate file.
                    807600
                    The DOS example was just to show you that one can divert o/p to a file, not to recommend it in your case.

                    If you want to write to diff file just copy or extend that code and this line here:
                    out = new PrintWriter( ...
                    Add:
                    File YourFileObjectGoesHere = new File("c:/my/log/file/subdir/log.txt");
                    if (!YourFileObjectGoesHere.isFile())
                      out = new PrintWriter(YourFileObjectGoesHere);
                    Something along that line.

                    Message was edited by:
                    abillconsl
                    • 7. Re: Writing system log into a separate file.
                      807600
                      Ok pal I tried to help you out. Are you there yet? Do you need more help?
                      • 8. Re: Writing system log into a separate file.
                        807600
                        hey It works!..but we did not yet put that in the system.....I almost forgot to come back to the thread....it got lost :o :D

                        Thanks a lot!
                        • 9. Re: Writing system log into a separate file.
                          807600
                          You are very welcome.