Netbeans magazine tutorial

Hi, I am working with the netbeans project that they gave me, and I need to check if the connection to the database (postgres) works well, and I notice that there are lines in the code

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 find out if the connection really works, because I can’t find the log file. so I searched the internet and I found this page link

but I really don’t understand what I have to do to see these messages. Can anybody help me?

0
source share
1 answer

Not sure which logging library you are using, but I assume you are using the standard java logging api (package java.util.logging) ...

You probably do not see this because you are using the DEBUG registration level and your project is set to print WARNING and higher than I assume. Therefore, if you want to quickly see what happens, either temporarily change the code:

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

OR create a logging.properties file in the project root directory, where you enable logging at the DEBUG level for the class or package for which you want to view the logs:

 com.mycompany.mypackgepath.myclass.level=DEBUG 

Please note that your project may already have such a file. You can also add more handlers to print log output in a file as well as in the netbeans console

 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 

You might want to check out this tutorial, for example: http://www.javapractices.com/topic/TopicAction.do?Id=143

Btw. the registrar must be private and final ;)

0
source

Source: https://habr.com/ru/post/1445781/


All Articles