log java.util.logging.Logger to a file

Discussion in 'Java' started by CD1, Feb 26, 2005.

  1. CD1

    CD1 Guest

    hi guys!

    I use an object from java.util.logging.Logger to log some error
    messages, like

    log.warning("some error");

    but it just displays on the screen. how can i tell it to log it to a
    file?
    i created the log with "Logger log = Logger.getLogger("error_log")".
    what should i do?

    see ya
     
    CD1, Feb 26, 2005
    #1
    1. Advertising

  2. "CD1" <> wrote in message
    news:...
    > hi guys!
    >
    > I use an object from java.util.logging.Logger to log some
    > error messages, like
    >
    > log.warning("some error");
    >
    > but it just displays on the screen. how can i tell it to log it
    > to a file?
    >
    > i created the log with:
    > "Logger log = Logger.getLogger("error_log")".
    > what should i do?
    >


    Create a 'FileHandler' object, and add it to your 'Logger' object; quick
    example:
    ...
    log.addHandler(new FileHandler("mylog.txt"));
    ...

    Check out:

    http://java.sun.com/j2se/1.4.2/docs/guide/util/logging/overview.html

    for details.

    I hope this helps.

    Anthony Borla
     
    Anthony Borla, Feb 26, 2005
    #2
    1. Advertising

  3. CD1

    Tilman Bohn Guest

    In message <>,
    CD1 wrote on 26 Feb 2005 03:34:52 -0800:

    [...]
    > but it just displays on the screen. how can i tell it to log it to a
    > file?
    > i created the log with "Logger log = Logger.getLogger("error_log")".
    > what should i do?


    You can start by reading the documentation:

    http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/package-summary.html

    and more to the point:

    http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/FileHandler.html

    --
    Cheers, Tilman

    `Boy, life takes a long time to live...' -- Steven Wright
     
    Tilman Bohn, Feb 26, 2005
    #3
  4. CD1

    CD1 Guest

    thanks! it worked =)
     
    CD1, Feb 26, 2005
    #4
    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:
    988
    Stefan Siegl
    Aug 27, 2003
  2. Gugle
    Replies:
    3
    Views:
    1,324
    Gugle
    Dec 12, 2006
  3. Frank
    Replies:
    1
    Views:
    941
    Daniel Pitts
    Dec 7, 2006
  4. Royan
    Replies:
    1
    Views:
    1,514
    Andrea Francia
    Apr 1, 2008
  5. cteb
    Replies:
    5
    Views:
    7,446
    Arne Vajhøj
    Oct 5, 2008
Loading...

Share This Page