使用 log4j,如何记录到 Windows 控制台?
我如何将日志记录转到Windows控制台(那个黑色的东西,CMD,COMMAND)? 我正在尝试使用 ConsoleAppender,但如果我做得正确的话,我不会这样做。
private static ConsoleAppender appender = new ConsoleAppender(new PatternLayout());
private Logger database;
Log() {
BasicConfigurator.configure();
database = Logger.getLogger("DATABASE");
database.addAppender(appender);
}
编辑:
第一个:此代码是一个示例,它比这个大
第二:在Netbeans控制台上完美运行。
How I do to the logging go to the Windows console (that black thing, CMD, COMMAND)?
I'm trying with ConsoleAppender, but I don't if I doing it right.
private static ConsoleAppender appender = new ConsoleAppender(new PatternLayout());
private Logger database;
Log() {
BasicConfigurator.configure();
database = Logger.getLogger("DATABASE");
database.addAppender(appender);
}
EDIT:
first: this code is a sample, it is bigger than this
second: on the console of Netbeans works perfectly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在记录信息之前设置所有附加程序。通常,log4j 的设置(包括添加附加程序)是在应用程序启动期间完成的。
在尝试更多操作之前,您应该阅读此处的文档。
You need to setup all the appenders before logging information. Usually the setting up of log4j (including adding appenders) is done during startup of your application.
You should read the documentation here before trying anything more.