springboot使JUL實(shí)現(xiàn)日志管理功能
第一步:設(shè)置logging.properties的內(nèi)容(放在resource文件夾下面)
#輸出兩種方式handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler.level= FINE#對(duì)日志的輸出進(jìn)行設(shè)置(主要是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#設(shè)置輸出格式j(luò)ava.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter#對(duì)文件設(shè)置輸出編碼格式(因?yàn)榘形淖址﹋ava.util.logging.FileHandler.encoding = UTF-8#對(duì)日志進(jìn)行追加java.util.logging.FileHandler.append = true #下面主要是為控制臺(tái)設(shè)置輸出格式j(luò)ava.util.logging.ConsoleHandler.level = FINEjava.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
第二步:編寫測(cè)試程序
@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'); }
第三步:控制臺(tái)查看相應(yīng)的輸出結(jié)果
九月 27, 2020 12:15:59 上午 com.test.testMd5 test信息: 你的姓名是:myName你的年齡是:3九月 27, 2020 12:15:59 上午 com.test.testMd5 test詳細(xì): 看看輸出了嗎九月 27, 2020 12:15:59 上午 com.test.testMd5 test信息: this is a test data
第四步:日志文件查看相應(yīng)的結(jié)果
到此這篇關(guān)于springboot使JUL實(shí)現(xiàn)日志管理功能的文章就介紹到這了,更多相關(guān)springboot日志管理內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. asp讀取xml文件和記數(shù)2. XML入門的常見(jiàn)問(wèn)題(一)3. 讀寫xml文件的2個(gè)小函數(shù)4. 告別AJAX實(shí)現(xiàn)無(wú)刷新提交表單5. 不同瀏覽器對(duì)XML的解析是不同的6. html小技巧之td,div標(biāo)簽里內(nèi)容不換行7. 阿里前端開(kāi)發(fā)中的規(guī)范要求8. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案9. IE6/IE7/IE8/IE9中tbody的innerHTML不能賦值的完美解決方案10. webpack高級(jí)配置與優(yōu)化詳解
