如何给自己程序通过命令行添加logging.properties文件
展开全部
最新的几个小工具都使用了Logger(java.util.logging.Logger), 大部分的信息都是finer级别的,只有少信息是info,但是字调试的时候需要使用finer级别,如何启用finer级别?
1, 创建一份自己的logging。properties, 内容可以如下
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.level = ALL
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
# 20MB limit to each file
java.util.logging.FileHandler.limit = 20000000
# Max out at 5 files of 'limit' size before replacing
java.util.logging.FileHandler.count = 3
# A pattern consists of a string that includes the following special components that will be replaced at runtime:
# "/" the local pathname separator
# "%t" the system temporary directory
# "%h" the value of the "user.home" system property
# "%g" the generation number to distinguish rotated logs
# "%u" a unique number to resolve conflicts
# "%%" translates to a single percent sign "%"
java.util.logging.FileHandler.pattern = mylog-%g.log
com.xxxx.yyyy..level = FINEST
2, 在执行的命令中加入
-Djava.util.logging.config.file="logging.properties"
比如你之前的执行命令如下
java.exe -classpath " xxxx/MySQL-connector-java-5.1.6-bin.jar;yyy/myUtility.jar" -Djava.util.logging.config.file="logging.properties" com.xxxx.yyyy.Main %*
3, 当你执行新的命令就可以看到在当前目录下面有个mylog-0.log文件的生成了
再次运行就有mylog-1.log
1, 创建一份自己的logging。properties, 内容可以如下
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.level = ALL
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
# 20MB limit to each file
java.util.logging.FileHandler.limit = 20000000
# Max out at 5 files of 'limit' size before replacing
java.util.logging.FileHandler.count = 3
# A pattern consists of a string that includes the following special components that will be replaced at runtime:
# "/" the local pathname separator
# "%t" the system temporary directory
# "%h" the value of the "user.home" system property
# "%g" the generation number to distinguish rotated logs
# "%u" a unique number to resolve conflicts
# "%%" translates to a single percent sign "%"
java.util.logging.FileHandler.pattern = mylog-%g.log
com.xxxx.yyyy..level = FINEST
2, 在执行的命令中加入
-Djava.util.logging.config.file="logging.properties"
比如你之前的执行命令如下
java.exe -classpath " xxxx/MySQL-connector-java-5.1.6-bin.jar;yyy/myUtility.jar" -Djava.util.logging.config.file="logging.properties" com.xxxx.yyyy.Main %*
3, 当你执行新的命令就可以看到在当前目录下面有个mylog-0.log文件的生成了
再次运行就有mylog-1.log
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询