springboot使JUL實現(xiàn)日志管理功能
第一步:設(shè)置logging.properties的內(nèi)容(放在resource文件夾下面)
#輸出兩種方式handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler.level= FINE#對日志的輸出進行設(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#對文件設(shè)置輸出編碼格式(因為包含中文字符)java.util.logging.FileHandler.encoding = UTF-8#對日志進行追加java.util.logging.FileHandler.append = true #下面主要是為控制臺設(shè)置輸出格式j(luò)ava.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'); }
第三步:控制臺查看相應的輸出結(jié)果
九月 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
第四步:日志文件查看相應的結(jié)果
到此這篇關(guān)于springboot使JUL實現(xiàn)日志管理功能的文章就介紹到這了,更多相關(guān)springboot日志管理內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 微信小程序?qū)崿F(xiàn)商品分類頁過程結(jié)束2. .NET 中配置從xml轉(zhuǎn)向json方法示例詳解3. 基于Surprise協(xié)同過濾實現(xiàn)短視頻推薦方法示例4. 不使用XMLHttpRequest對象實現(xiàn)Ajax效果的方法小結(jié)5. 以PHP代碼為實例詳解RabbitMQ消息隊列中間件的6種模式6. 推薦一個好看Table表格的css樣式代碼詳解7. ASP新手必備的基礎(chǔ)知識8. ASP常用日期格式化函數(shù) FormatDate()9. vue-electron中修改表格內(nèi)容并修改樣式10. AJAX實現(xiàn)文件上傳功能報錯Current request is not a multipart request詳解
