netbeans日志记录教程 [英] netbeans logging tutorial
问题描述
我正在与一个netbeans项目合作,他们让我继续工作,我需要检查与数据库(postgres)的连接是否工作良好,而且我注意到代码中有些行像
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);
然后
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?
推荐答案
不确定使用的是哪种日志记录库,但我认为您使用的是标准的Java日志记录api(java.util.logging包)...
Not sure which logging library you use, but I presume you use the standard java logging api (java.util.logging package) ...
您可能看不到它,因为您使用的是DEBUG级别的日志记录,并且您的项目设置为打印WARNING及以上,我相信.因此,如果您要快速查看发生了什么,请暂时将代码更改为:
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");
或在项目的根目录中创建logging.properties文件,您将在其中为要查看其日志的类或包启用DEBUG级别的日志记录:
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
请注意,您的项目中可能已经有这样的文件.另外,您可以添加更多处理程序,以便将日志输出打印到文件以及netbeans控制台
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
例如,您可能想查看本教程: http://www. javapractices.com/topic/TopicAction.do?Id=143
You might want to check this tutorial for example: http://www.javapractices.com/topic/TopicAction.do?Id=143
顺便说一句.记录器应为private
和final
;)
Btw. the logger should be private
and final
;)
这篇关于netbeans日志记录教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!