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

Discussion in 'Java' started by Michael T. Peterson, Sep 9, 2003.

  1. 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
     
    Michael T. Peterson, Sep 9, 2003
    #1
    1. Advertisements

  2. Michael T. Peterson

    Steven Coco Guest

    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.
     
    Steven Coco, Sep 9, 2003
    #2
    1. Advertisements

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

    Cheers,

    Michael
     
    Michael T. Peterson, Sep 9, 2003
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.