我有以下示例代码:
import java.util.logging.Logger;
public class LoggingExample {
private static final Logger LOGGER = Logger.getLogger(
Thread.currentThread().getStackTrace()[0].getClassName() );
public static void main(String[] args) {
LOGGER.setLevel(Level.ALL);
LOGGER.info("Logging an INFO-level message");
LOGGER.fine("Logging an INFO-level message2");
}
}
输出到控制台:
05/06/2014 12:07:09 ztesting.Loger.LoggingExample main
INFO: Logging an INFO-level message
我有几个问题:
P.S。我使用的是netbeans 6.9
还尝试使用以下链接,它让我没有
Is there any way to remove the information line from java.util.logging.Logger output?
How do I get java logging output to appear on a single line?
感谢您的帮助..
答案 0 :(得分:1)
您可以在java.util.logging
的不同教程中回答您的大部分问题。一个例子here
您还应该阅读javadoc。
"Can I not display the first line "05/06/2014 12:07:09 ztesting.Loger.LoggingExample main"
是的,使用Formatters
"Can I block the output to console completely, meaning I would only set output to a log file."
是,在configuration文件中设置日志级别,过滤器或处理程序
"The entire output is in red, can I set the output to be in different colors according to the level?"
这是Netbeans特有的,我个人不会使用,所以我无法回答。