至于存到数据游纳库,那就得再打开log日志找到所需要的信息做 *** 作了。
import java.util.logging.*
import java.io.* public class MemoryHandlerTest { FileHandler fhandler Logger logger MemoryHandler mhandler MemoryHandlerTest() { try { fhandler = new FileHandler("my.log") int numRec = 5 mhandler = new MemoryHandler(fhandler, numRec, Level.OFF) logger = Logger.getLogger("com.mycompany") logger.addHandler(mhandler) } catch (IOException e) {
} } public static void main(String args[]) { MemoryHandlerTest mt = new MemoryHandlerTest() int trigger = (int) (Math.random() * 100) for (int i = 1 i < 100 i++) { mt.logger.log(Level.INFO, "日志记录" + i) if (i == 旦顷trigger) { mt.mhandler.push() break } } } }
最新的几个小工具都使用了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.jaryyy/myUtility.jar" -Djava.util.logging.config.file="logging.properties" com.xxxx.yyyy.Main %*
3, 当你执行新的命令就可以看到在当前目录下面有个mylog-0.log文件的生成了
再次运行就有mylog-1.log
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)