Java write record or message to log file problem
try {
// Cr开发者_开发百科eate an appending file handler
boolean append = true;
FileHandler handler = new FileHandler("my.log", append);
// Add to the desired logger
Logger logger = Logger.getLogger("com.mycompany");
logger.log(Level.INFO, "This is info message");
logger.addHandler(handler);
} catch (IOException e) {
}
My problem is when i open my.log file i don't see the text "This is info message" but just
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
</log>
Can anyone point me out where is problem???
I think you should add handler before you log something.
You should set the appender before logging anything is logged
try {
// Create an appending file handler
boolean append = true;
FileHandler handler = new FileHandler("my.log", append);
// Add to the desired logger
Logger logger = Logger.getLogger("com.mycompany");
logger.addHandler(handler);
logger.log(Level.INFO, "This is info message");
} catch (IOException e) {
}
Quoting from the docs:
Each Logger has a "Level" associated with it.
Maybe the level configured for this logger is too high for INFO level messages to show up.
精彩评论