Netbeans Logger

2019-06-04 07:35发布

I've been developping using Netbeans as an IDE for Java. When Netbeans surrounds a statement within a try-catch block it uses something like Logger.getLogger(MyTestClass.class.getName()).log(Level.SEVERE, null, ex); in the catch region. My questions are

  1. What and where is the log file created by this sentence?
  2. Should I create it? If so, how?

Cheers !

1条回答
太酷不给撩
2楼-- · 2019-06-04 07:57

The logger is always available. You can create one with a custom name. You write the logging to a file (with FileHandler):

Logger logger = Logger.getLogger("MyLog"); 
fh = new FileHandler("C:/temp/test/MyLogFile.log");  
logger.addHandler(fh);

By default logging is written to the console. you can enable java console: http://www.java.com/en/download/help/javaconsole.xml

hope it helps

查看更多
登录 后发表回答