Java将记录或消息写入日志文件问题
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.log(Level.INFO, "This is info message");
logger.addHandler(handler);
} catch (IOException e) {
}
我的问题是,当我打开 my.log 文件时,我没有看到文本“这是信息消息”,但
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
</log>
有人能指出我问题出在哪里吗???
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.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???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您应该在记录某些内容之前添加处理程序。
I think you should add handler before you log something.
您应该在记录任何内容之前设置附加程序
You should set the appender before logging anything is logged
引用文档:
也许为此记录器配置的级别太高,无法显示 INFO 级别消息。
Quoting from the docs:
Maybe the level configured for this logger is too high for INFO level messages to show up.