Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

How to trap error messages or general messages with time stamp

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To redirect standard error and output to different files, you can use grouping:

% (java MyClass > myout) >& myerror
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic