The Artima Developer Community
Sponsored Link

Java Answers Forum
Logfiles

1 reply on 1 page. Most recent reply: Jan 23, 2003 3:39 AM by vijaya

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
vijaya

Posts: 3
Nickname: vijaya
Registered: Jan, 2003

Logfiles Posted: Jan 20, 2003 5:36 AM
Reply to this message Reply
Advertisement
Hi! How to convert System.err and print statements to error.log file. Reards. Vijaya.


vijaya

Posts: 3
Nickname: vijaya
Registered: Jan, 2003

Re: Logfiles Posted: Jan 23, 2003 3:39 AM
Reply to this message Reply
Hi!
I got the answer to my qst.
There are three basic approaches I can think of:
(1) Use OS-level output redirection, e.g.

java MyClass 1> output.log 2> error.log

or

java MyClass 1> all_output.log 2>&1

I believe the same syntax works in Unix and Windows here. This is easy,

and requires no changes inside your code.

(2) Use System.setOut() and System.setErr() within your program to

redirect the output to a stream writing to a file, as Layne suggests.

Also pretty easy.

(3) Replace the various println() statements with more advanced logging

techniques, using classes such as those in java.util.logging or the

Log4J package. This is more work than the other two, but may be more

rewarding as it will allow you much more flexibility to make other

adjustments later. E.g. you may initially decide that loggers will

simply write messages to the screen. Later you can easily revise this to

write all messages to one detailed log file, and also write only errors

and important non-error messages to a different file, and also create a

pop-up window to inform the user of errors. (For example.) These later

changes can be made by making changes just to the code that creates and

configures the loggers (or maybe just to configuration files which are

read by your code). Most of the code in the other classes that do the

logging will not need to be changed at all.

I like the third option for a big project, where the power and

flexibility I get later makes it worthwhile to spend a little extra

energy at teh beginning to set up logging. For smaller projects, the

first two options may be appropriate.

Regards.
Vijaya.

Flat View: This topic has 1 reply on 1 page
Topic: how to compile servlet source codes? Previous Topic   Next Topic Topic: help with this preparedStatment

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use