第一步:設置logging.properties的內容(放在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 #對日志的輸出進行設置(主要是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 #設置輸出格式 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 = 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" ); } |
第三步:控制臺查看相應的輸出結果
九月 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日志管理內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/xgysimida/article/details/108819682