date and message on same line using logging API

Hi, Using the standard library for logging, i.e. java.util.logging, I was wondering if there is any way to display the date and the message on the same line. Currently if you do something like logger.info("My Message"); The logger will display a timestamp followed by the class name and method where the trace is coming from and then the next line will be "My Message". I would like to display all of this information on the same line or even cut the timestamp out altogether. If anyone knows how, I would love to hear. Many thanks!

Thanks Thomas for the great article. It was very useful! I am a bit puzzled by the behaviour of my Formatter though. I extended Formatter class and overrode the format() method and defined my format like I wanted. Then I used the ConsoleHandler and set the format to my Format class. The puzzling thing is at runtime, the top line is formatted exactly as I specified, but then I get 2 more lines that is like it was before with no formatting. Why does this happen? Here is a sample output:

The top line is what I want. How do I get rid of the next 2 lines? Thanks so much for your help! Barry

Thomas Paul

mister krabs
Ranch Hand

Posts: 13974

posted 14 years ago

This is a common mistake. The problem is that your Logger object has a parent Logger object that defaults to print to the console. it's a pain in the neck and I'm not sure why it was implemented this way but there is a way to handle it.

wow, that's pretty odd! Your work around does work though. Thanks for the help! Barry

Adam Hardy

Ranch Hand

Posts: 567

posted 14 years ago

I have just been reading through old posts to figure out how to set up java sdk 1.4 logging the way I like. I think in this situation you could just as easily go:

and it would solve the double logging to console issue, instead of looping through the parents to turn them off. I couldn't reconstruct a situation like this though - the way I have configured logging with a logging.properties file, my logger doesn't actually have its own handler, it inherits it from its parent. My two cents. Adam

I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.