• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to trap error messages or general messages with time stamp  RSS feed

 
preddy Narra
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How to trap error messages or general messages with time stamp.
I mean i want to redirect my error messages to any external file.
i would appreciate if anybody give me the solution.

---------------------
PcReddy
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16048
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean that you have used System.out.println(...) all over your program and that you want to capture the console output into a file? If yes, then use '>' on the command line to redirect the console output to a file:

java com.mypackage.MyProgram > output.txt

If you want better debug logging, use a logging API such as java.util.logging or Log4J. With those, you can have timestamps added to your log messages automatically.
 
preddy Narra
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi young,

Suppose while execution of a program,errors came.I want to redirect these errors to an separate file from my program.

If anybody see that file,then they will able to know the details regarding program,errors and execution date.

thanks for ur response.

-----------------------

PcReddy
 
Justin Lewis
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To redirect standard error and output to different files, you can use grouping:

% (java MyClass > myout) >& myerror
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding timestamp would be fun. You could replace the System.out writer with your own that puts a timestamp in front of every line.

System.setOut( new MyPrintStream( someOutputStream ) );

I don't know how you'd decide when to write timestamps on methods other than PrintLn.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!