0

hi i'm working with a netbeans project, that they gave me to work on, and i need to check if the connection to the database (postgres) are working well, and i notice that there are lines in the code like

static Logger log = Logger.getLogger(getNivel.class);

then

if (user != null) {
            log.debug("Usuario identificado: " + user.getIdUsuario() + "obteniendo su cuadro de mandos");

but i don't know how to see if the connection is actually working, because i can't find the log file. so i searched the internet and i found this page link

but i don't really understand what i should do to see those messages. Can anybody help me?

4

1 回答 1

0

不确定您使用哪个日志记录库,但我认为您使用标准的 java 日志记录 API(java.util.logging 包)...

您可能看不到它,因为您使用的是 DEBUG 级别的日志记录,并且您的项目设置为打印 WARNING 及以上我相信。因此,如果您要快速查看发生了什么,请暂时将代码更改为:

if (user != null) {
        log.severe("Usuario identificado: " + user.getIdUsuario() + "obteniendo su cuadro de mandos");

或者在项目的根目录中创建 logging.properties 文件,您将在其中为要查看日志的类或包启用 DEBUG 级别的日志记录:

com.mycompany.mypackgepath.myclass.level=DEBUG

请注意,您的项目中可能已经存在这样的文件。您还可以添加更多处理程序,以便将日志输出打印到文件以及 netbeans 控制台

handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=ALL
java.util.logging.FileHandler.pattern = %h/Library/Logs/xd%g-%u.log
java.util.logging.FileHandler.limit = 10485760
java.util.logging.FileHandler.count = 2
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.encoding = UTF8

您可能想查看本教程,例如:http ://www.javapractices.com/topic/TopicAction.do?Id=143

顺便提一句。记录器应该是privatefinal;)

于 2012-04-22T15:34:42.263 回答