简体   繁体   中英

netbeans logging tutorial

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?

Not sure which logging library you use, but I presume you use the standard java logging api (java.util.logging package) ...

You dont probably see it because you are using DEBUG level of logging and your project is set to print WARNING and above I believe. So if you what to quickly see whats going on, either change temporarily the code to:

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

OR create logging.properties file in the root of you project, where you will enable logging on DEBUG level for the class or package for which you want to see the logs:

com.mycompany.mypackgepath.myclass.level=DEBUG

Note, that there might be already such a file in your project. Also you can add more handlers in order to print the log output to a file as well as to 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 this tutorial for example: http://www.javapractices.com/topic/TopicAction.do?Id=143

Btw. the logger should be private and final ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM