Results 1 to 12 of 12
  1. #1
    JonJacobs is offline Member
    Join Date
    Jul 2010
    Posts
    34
    Rep Power
    0

    Default Logger + FileHandler problems

    I tried to create a logger that logs to a file. I expected simple text, but it came out xml.


    logger = Logger.getLogger("MyConnect");
    fh = new FileHandler(fn);
    logger.addHandler(fh);
    logger.setLevel(Level.ALL);

    All my entries to the log were at the info level.

    Strangely, I did get simple text like I wanted, but in the command window instead of in the file. I didn't expect that.

    What am I doing wrong? (probably a lot).

    Thanks,
    Jon Jacobs
    This message was composed entirely from recycled electrons.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    JonJacobs is offline Member
    Join Date
    Jul 2010
    Posts
    34
    Rep Power
    0

    Default

    I don't know about that. How do I examine or set that? On a freshly created logger and file handler, the configurations have to be whatever the defaults are.

    Thanks,
    Jon Jacobs
    This message was composed entirely from recycled electrons.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by JonJacobs View Post
    I don't know about that. How do I examine or set that? On a freshly created logger and file handler, the configurations have to be whatever the defaults are.

    Thanks,
    Maybe there's a default configuration file in your jre directory, named logging.properties. It configures the Handlers for the Logger(s); check if it has a line as:

    Java Code:
    handlers= java.util.logging.ConsoleHandler
    If so, a ConsolerHandler is configured, hence the stderr output. Read all about it in the API for the Logger framework.

    kind regards,

    Jos

  5. #5
    JonJacobs is offline Member
    Join Date
    Jul 2010
    Posts
    34
    Rep Power
    0

    Default

    Okay, that would explain why I also get console output as well as file output. I'm okay with that; I just thought it strange. My main concern is that I added a FileHandler, not an XML handler, so why is my file output in xml format?

    Thanks,
    Jon Jacobs
    This message was composed entirely from recycled electrons.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by JonJacobs View Post
    Okay, that would explain why I also get console output as well as file output. I'm okay with that; I just thought it strange. My main concern is that I added a FileHandler, not an XML handler, so why is my file output in xml format?

    Thanks,
    I bet you didn't read the API documentation for the FileHandler class because it reads:

    •java.util.logging.FileHandler.formatter specifies the name of a Formatter class to use (defaults to java.util.logging.XMLFormatter)
    kind regards,

    Jos

  7. #7
    JonJacobs is offline Member
    Join Date
    Jul 2010
    Posts
    34
    Rep Power
    0

    Default

    Actually I was reading documentation for the Logger class, which is what I thought you were sending me to. Formatter class. That's what I needed, I'm sure.

    Thank you,
    Jon Jacobs
    This message was composed entirely from recycled electrons.

  8. #8
    JonJacobs is offline Member
    Join Date
    Jul 2010
    Posts
    34
    Rep Power
    0

    Default

    I searched the Web for info on the Formatter class and accidentally found the API documentation you were talking about. I see now. I found the SimpleFormatter class and used that, and got exactly what I wanted.

    Thanks for your help,
    Jon Jacobs
    This message was composed entirely from recycled electrons.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by JonJacobs View Post
    I searched the Web for info on the Formatter class and accidentally found the API documentation you were talking about. I see now. I found the SimpleFormatter class and used that, and got exactly what I wanted.

    Thanks for your help,
    You should never attempt to program any Java code without having the complete API documentation available. Here it is. Bookmark it or download the entire thing.

    kind regards,

    Jos

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by JosAH View Post
    You should never attempt to program any Java code without having the complete API documentation available. Here it is. Bookmark it or download the entire thing.

    kind regards,

    Jos
    I've miss lots of discussion over here, but I wants add something on this.

    I agreed with Jos, and I've seen that Jos and most of the other members are mentioned highlighting about this. My suggestion is better to keep an offline of the doc in the PC, and it's possible to attach with most of the IDEs available nowadays.

  11. #11
    JonJacobs is offline Member
    Join Date
    Jul 2010
    Posts
    34
    Rep Power
    0

    Default

    >having the complete API documentation available

    >better to keep an offline of the doc

    Done.

    Thanks,
    Jon Jacobs
    This message was composed entirely from recycled electrons.

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. How to encode a fileHandler to output french characters ?
    By l.najm@acteos.com in forum Advanced Java
    Replies: 4
    Last Post: 04-22-2010, 09:21 AM
  2. Replies: 2
    Last Post: 03-09-2010, 08:18 AM
  3. Logger and file lock
    By segolas in forum Advanced Java
    Replies: 3
    Last Post: 01-14-2010, 04:02 PM
  4. Java logging - log file location for FileHandler
    By kfir.wolfson@gmail.com in forum Advanced Java
    Replies: 2
    Last Post: 03-24-2009, 08:22 AM
  5. Help with key Logger in java
    By paul in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 05:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •