第一步:設(shè)置logging.properties的內(nèi)容(放在resource文件夾下面)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#輸出兩種方式 handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler .level= FINE #對日志的輸出進(jìn)行設(shè)置(主要是file類) #java.util.logging.FileHandler.pattern = %h/java%u.log #下面的是輸出到制定的目錄下 java.util.logging.FileHandler.pattern = D:\\software\\idea\\idealianxicode\\springboot1\\src\\main\\resources/java%u.log #日志限制大小 java.util.logging.FileHandler.limit = 5000 java.util.logging.FileHandler.count = 1 #設(shè)置輸出格式 java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter #對文件設(shè)置輸出編碼格式(因為包含中文字符) java.util.logging.FileHandler.encoding = UTF- 8 #對日志進(jìn)行追加 java.util.logging.FileHandler.append = true #下面主要是為控制臺設(shè)置輸出格式 java.util.logging.ConsoleHandler.level = FINE java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter |
第二步:編寫測試程序
1
2
3
4
5
6
7
8
9
10
11
12
13
|
@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" ); } |
第三步:控制臺查看相應(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實現(xiàn)日志管理功能的文章就介紹到這了,更多相關(guān)springboot日志管理內(nèi)容請搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!
原文鏈接:https://blog.csdn.net/xgysimida/article/details/108819682