• Post Reply Bookmark Topic Watch Topic
  • New Topic

using java.util.Logging to generate a txt log file  RSS feed

 
lee kris
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there,

java.util.logging.
I am trying to use this logging mechanism for the first time. I saw a couple of examples here and there and most of the time whenever here is a use of a FileHandler(which allows one to write to a file), the file that is written out is a XML file. can I somehow control this so that the file produced is just the same format as though I was using a ConsoleHandeler (meaning a plain text file).

Thanks.
 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The response to your problem is the Formatter to use.

By default, FileHandler uses XMLFormatter, ConsoleHandler uses SimpleFormatter.

So you can use a FileHandler with a SimpleFormatter (method setFormatter in Handler)
 
Adam Richards
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an abbreviated example of how a file formatter might look. You would of course, need to adapt it to your needs:
 
Ray Horn
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can update the 'jre/lib/logging.properties' file so that the default formatter for a new FileHandler uses java.util.logging.SimpleFormatter.
In the file released in jdk1.5.0_04 change line 40 from:

java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter

to

java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!