[Q] Howto customize output from java.util.logging API in Java 1.4

  • Thread starter Michael T. Peterson
  • Start date
M

Michael T. Peterson

Hi,

I would like to customize the spew printed by the java.util.logging.Logger,
but can't really find any examples or instructions about how this may be
done. For example, the code

LogRecord record = new LogRecord( Level.INFO, "This is a
message." );
logger.log( record );

produces

Sep 8, 2003 7:15:38 PM com.mazama.utils.Trace println
INFO: This is a message.

I would like to be able to customize the output so that I may have the
Logger print the message either of 3 ways:

Sep 8, 2003 7:15:38 PM com.mazama.utils.Trace println INFO: This is a
message.
or
INFO: This is a message.
or
Sep 8, 2003 7:15:38 PM com.mazama.utils.Trace println

Thanks, in advance.

Michael
 
S

Steven Coco

Michael said:
I would like to be able to customize the output

From the handy Core Java 2 books: You need to extend the Formatter
class and override the method

String format(LogRecord record)

Look at the docs for getHead(Handler) and getTail(Handler) in case
either is appropriate for your thing, and see formatMessage(LogRecord)
for the method that produces your undesired output I think.

You install the formatter into a handler by the setFormatter method.

Good luck.

Peace,
Steev.
 
M

Michael T. Peterson

Thanks for the reply and the reference. I think I need to pick up that
book.

Cheers,

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top