springboot使JUL實現日志管理功能
第一步:設置logging.properties的內容(放在resource文件夾下面)
#輸出兩種方式handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler.level= FINE#對日志的輸出進行設置(主要是file類)#java.util.logging.FileHandler.pattern = %h/java%u.log#下面的是輸出到制定的目錄下java.util.logging.FileHandler.pattern = D:softwareideaidealianxicodespringboot1srcmainresources/java%u.log#日志限制大小java.util.logging.FileHandler.limit = 5000java.util.logging.FileHandler.count = 1#設置輸出格式java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter#對文件設置輸出編碼格式(因為包含中文字符)java.util.logging.FileHandler.encoding = UTF-8#對日志進行追加java.util.logging.FileHandler.append = true #下面主要是為控制臺設置輸出格式java.util.logging.ConsoleHandler.level = FINEjava.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
第二步:編寫測試程序
@Test public void test() throws IOException { InputStream resourceAsStream = testMd5.class.getClassLoader().getResourceAsStream('logging.properties'); LogManager logManager = LogManager.getLogManager(); logManager.readConfiguration(resourceAsStream); Logger logger = Logger.getLogger('com.testMd5'); int age = 3; String name ='myName'; logger.info('你的姓名是:'+name+'你的年齡是:'+age); logger.fine('看看輸出了嗎'); logger.info('this is a test data'); }
第三步:控制臺查看相應的輸出結果
九月 27, 2020 12:15:59 上午 com.test.testMd5 test信息: 你的姓名是:myName你的年齡是:3九月 27, 2020 12:15:59 上午 com.test.testMd5 test詳細: 看看輸出了嗎九月 27, 2020 12:15:59 上午 com.test.testMd5 test信息: this is a test data
第四步:日志文件查看相應的結果
到此這篇關于springboot使JUL實現日志管理功能的文章就介紹到這了,更多相關springboot日志管理內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章: