Results 1 to 12 of 12
Thread: Logger + FileHandler problems
- 08-17-2010, 08:30 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 34
- Rep Power
- 0
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.
- 08-18-2010, 04:47 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
How about the configurations of the logger?
- 08-18-2010, 12:44 PM #3
Member
- Join Date
- Jul 2010
- Posts
- 34
- Rep Power
- 0
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.
- 08-18-2010, 01:40 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
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:
If so, a ConsolerHandler is configured, hence the stderr output. Read all about it in the API for the Logger framework.Java Code:handlers= java.util.logging.ConsoleHandler
kind regards,
Jos
- 08-18-2010, 01:59 PM #5
Member
- Join Date
- Jul 2010
- Posts
- 34
- Rep Power
- 0
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.
- 08-18-2010, 02:16 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 08-18-2010, 02:29 PM #7
Member
- Join Date
- Jul 2010
- Posts
- 34
- Rep Power
- 0
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.
- 08-18-2010, 02:59 PM #8
Member
- Join Date
- Jul 2010
- Posts
- 34
- Rep Power
- 0
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.
- 08-18-2010, 03:24 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
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
- 08-19-2010, 01:49 PM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 08-19-2010, 02:11 PM #11
Member
- Join Date
- Jul 2010
- Posts
- 34
- Rep Power
- 0
>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.
- 08-19-2010, 02:19 PM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
That's great. And also if you've solve the problem, please mark the thread solved. :)
Similar Threads
-
How to encode a fileHandler to output french characters ?
By l.najm@acteos.com in forum Advanced JavaReplies: 4Last Post: 04-22-2010, 09:21 AM -
Weird error with FileHandler, java.util.logging.FileHandler
By nmvictor in forum New To JavaReplies: 2Last Post: 03-09-2010, 08:18 AM -
Logger and file lock
By segolas in forum Advanced JavaReplies: 3Last Post: 01-14-2010, 04:02 PM -
Java logging - log file location for FileHandler
By kfir.wolfson@gmail.com in forum Advanced JavaReplies: 2Last Post: 03-24-2009, 08:22 AM -
Help with key Logger in java
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:14 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks