[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. Advertising

  2. Michael T. Peterson

    Steven Coco Guest

    Re: [Q] Howto customize output from java.util.logging API in Java1.4

    Michael T. Peterson wrote:

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

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

    Cheers,

    Michael
    "Steven Coco" <> wrote in message
    news:0sj7b.8624$...
    > Michael T. Peterson wrote:
    >
    > > 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.
    >
    Michael T. Peterson, Sep 9, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Siegl
    Replies:
    0
    Views:
    939
    Stefan Siegl
    Aug 27, 2003
  2. janne
    Replies:
    0
    Views:
    9,442
    janne
    Sep 10, 2004
  3. Symz
    Replies:
    5
    Views:
    11,909
  4. Robert Mark Bram
    Replies:
    0
    Views:
    572
    Robert Mark Bram
    Apr 30, 2007
  5. Royan
    Replies:
    1
    Views:
    1,409
    Andrea Francia
    Apr 1, 2008
Loading...

Share This Page