Spring?Boot?Actuator管理日志的實(shí)現(xiàn)
為了解決以下兩個(gè)問(wèn)題:
1、單JAR包應(yīng)用查看日志需要的時(shí)候如果需要遠(yuǎn)程訪問(wèn)服務(wù)器登錄查看日志,那樣相對(duì)比較麻煩
2、生產(chǎn)環(huán)境為了解決BUG需要臨時(shí)更換日志級(jí)別,總不能重啟服務(wù)來(lái)解決吧
所以使用了actuator 其中的部分來(lái)解決這兩個(gè)問(wèn)題。
首先在POM文件中引入actuator依賴:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>${spring-boot.version}</version> </dependency>
配置文件中配置:
management.endpoints.web.base-path=/actuator management.endpoints.web.exposure.include=logfile,loggers management.endpoint.health.show-details=always logging.file.name=logs/EL-3KJ/EL-3KJ.log
然后直接可以訪問(wèn) http://localhost:8085/actuator
得到下列結(jié)果:
{"_links":{
"self"{"href":"http://localhost:8085/actuator","templated":false},
"logfile: {"href":"http://localhost:8085/actuator/logfile","templated":false},"loggers":{"href":"http://localhost:8085/actuator/loggers","templated":false},"loggers-name":{"href":"http://localhost:8085/actuator/loggers/{name}","templated":true}}}
其中
- logfile 是查看日志文件
- loggers是查看日志級(jí)別
- loggers/{name}是更改日志級(jí)別
前端參考代碼:
<TabPane label="接口日志" name="name3"> 級(jí)別: <RadioGroup v-model="loglevel" type="button" size="small" @on- change="lvChange()"> <Radio label="ERROR"></Radio> <Radio label="INFO"></Radio> <Radio label="DEBUG"></Radio> </RadioGroup> <br/><br/> 文件:<a :href="logfileurl" rel="external nofollow" target="_blank" > 查看</a> </TabPane> this.logfileurl = res.dataApi+"actuator/logfile"; this.loglevelurl = res.dataApi+"actuator/loggers/root"; getLogLevel(){ this.ajax_get({ url: this.loglevelurl, params: {}, }).then((res) => { this.loglevel=res.configuredLevel }); }, lvChange(){ this.changeLogLevel(this.loglevel) }, changeLogLevel(level){ this.ajax_post({ url: this.tenant.dataApi + "actuator/loggers/root", params: {'configuredLevel':level}, }).then((res) => { this.spinShow = false; if (!res.code) { this.$Notice.success({ title:'更改日志級(jí)別為'+level, desc:res.msg }); } else { this.$Notice.error({ title:'更改日志級(jí)別失敗', desc:res.msg }); } }); }
最終效果如下:
到此這篇關(guān)于Spring Boot Actuator管理日志的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Spring Boot Actuator管理日志內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- SpringBoot四大神器之Actuator的使用小結(jié)
- 詳解配置spring-boot-actuator時(shí)候遇到的一些小問(wèn)題
- SpringBoot 監(jiān)控管理模塊actuator沒(méi)有權(quán)限的問(wèn)題解決方法
- spring boot starter actuator(健康監(jiān)控)配置和使用教程
- springboot 使用Spring Boot Actuator監(jiān)控應(yīng)用小結(jié)
- 詳解spring-boot actuator(監(jiān)控)配置和使用
- Spring Boot Actuator監(jiān)控端點(diǎn)小結(jié)
- Spring Boot Actuator監(jiān)控的簡(jiǎn)單使用方法示例代碼詳解
- Spring Boot Actuator執(zhí)行器運(yùn)行原理詳解
相關(guān)文章
java解析JT808協(xié)議的實(shí)現(xiàn)代碼
這篇文章主要介紹了java解析JT808協(xié)議的實(shí)現(xiàn)代碼,需要的朋友可以參考下2020-03-03java微信企業(yè)號(hào)開發(fā)之開發(fā)模式的開啟
這篇文章主要為大家詳細(xì)介紹了java微信企業(yè)號(hào)開發(fā)之開發(fā)模式的開啟方法,感興趣的小伙伴們可以參考一下2016-06-06Java實(shí)現(xiàn)簡(jiǎn)單的貪吃蛇游戲
這篇文章主要介紹了Java實(shí)現(xiàn)簡(jiǎn)單的貪吃蛇游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-07-07Java TreeSet實(shí)現(xiàn)學(xué)生按年齡大小和姓名排序的方法示例
這篇文章主要介紹了Java TreeSet實(shí)現(xiàn)學(xué)生按年齡大小和姓名排序的方法,涉及java類型轉(zhuǎn)換、遍歷、比較等相關(guān)操作技巧,需要的朋友可以參考下2017-09-09Springboot集成swagger實(shí)現(xiàn)方式
這篇文章主要介紹了Springboot集成swagger實(shí)現(xiàn)方式,通過(guò)簡(jiǎn)單的示例代碼詳細(xì)描述了實(shí)現(xiàn)過(guò)程步驟,有需要的朋友可以借鑒參考下,希望可以有所幫助2021-08-08Spring Boot實(shí)現(xiàn)qq郵箱驗(yàn)證碼注冊(cè)和登錄驗(yàn)證功能
這篇文章主要給大家介紹了關(guān)于Spring Boot實(shí)現(xiàn)qq郵箱驗(yàn)證碼注冊(cè)和登錄驗(yàn)證功能的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12WebSocket無(wú)法注入屬性的問(wèn)題及解決方案
這篇文章主要介紹了WebSocket無(wú)法注入屬性的問(wèn)題及解決方法,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-09-09springboot使用dubbo和zookeeper代碼實(shí)例
這篇文章主要介紹了springboot使用dubbo和zookeeper代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-11-11java實(shí)現(xiàn)基于SGIP協(xié)議開發(fā)聯(lián)通短信的方法
這篇文章主要介紹了java實(shí)現(xiàn)基于SGIP協(xié)議開發(fā)聯(lián)通短信的方法,涉及java短信發(fā)送的相關(guān)實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07