• Post Reply Bookmark Topic Watch Topic
  • New Topic

System.out date/time

 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

Just a quick question.

Any of you lot know how I can get the date/time (in some sort or format) on every system.out I put in a system?

I could create a Date()/SimpleDateFormat() thingy and then stick that on the start of every System.out, but it seems a little messy. Or is that the only way?

Cheers
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should maybe consider a propper logging framework. They can be configured to format a timestamp via a properties file usually.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree that for a production quality application, using a logging framework such as log4j is your best option.

However, if you really just want to add a timestamp to your System.out.println, just code a static method in a utility class to do it, and then call that method instead of System.out.println().

example:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!