使用Spring Boot的LoggersEndpoint管理日志級(jí)別
序
本文主要研究一下springboot的LoggersEndpoint
LoggersEndpoint
/** * {@link Endpoint @Endpoint} to expose a collection of {@link LoggerConfiguration}s. * * @author Ben Hale * @author Phillip Webb * @author HaiTao Zhang * @since 2.0.0 */ @Endpoint(id = "loggers") public class LoggersEndpoint { private final LoggingSystem loggingSystem; private final LoggerGroups loggerGroups; /** * Create a new {@link LoggersEndpoint} instance. * @param loggingSystem the logging system to expose * @param loggerGroups the logger group to expose */ public LoggersEndpoint(LoggingSystem loggingSystem, LoggerGroups loggerGroups) { Assert.notNull(loggingSystem, "LoggingSystem must not be null"); Assert.notNull(loggerGroups, "LoggerGroups must not be null"); this.loggingSystem = loggingSystem; this.loggerGroups = loggerGroups; } //...... }
springboot的actuator定義了LoggersEndpoint,它構(gòu)造器依賴(lài)loggingSystem及l(fā)oggerGroups
loggers
@ReadOperation public Map<String, Object> loggers() { Collection<LoggerConfiguration> configurations = this.loggingSystem.getLoggerConfigurations(); if (configurations == null) { return Collections.emptyMap(); } Map<String, Object> result = new LinkedHashMap<>(); result.put("levels", getLevels()); result.put("loggers", getLoggers(configurations)); result.put("groups", getGroups()); return result; } private NavigableSet<LogLevel> getLevels() { Set<LogLevel> levels = this.loggingSystem.getSupportedLogLevels(); return new TreeSet<>(levels).descendingSet(); } private Map<String, LoggerLevels> getLoggers(Collection<LoggerConfiguration> configurations) { Map<String, LoggerLevels> loggers = new LinkedHashMap<>(configurations.size()); for (LoggerConfiguration configuration : configurations) { loggers.put(configuration.getName(), new SingleLoggerLevels(configuration)); } return loggers; } private Map<String, LoggerLevels> getGroups() { Map<String, LoggerLevels> groups = new LinkedHashMap<>(); this.loggerGroups.forEach((group) -> groups.put(group.getName(), new GroupLoggerLevels(group.getConfiguredLevel(), group.getMembers()))); return groups; }
LoggersEndpoint定義了loggers的read操作,返回levels、loggers、groups
loggerLevels
@ReadOperation public LoggerLevels loggerLevels(@Selector String name) { Assert.notNull(name, "Name must not be null"); LoggerGroup group = this.loggerGroups.get(name); if (group != null) { return new GroupLoggerLevels(group.getConfiguredLevel(), group.getMembers()); } LoggerConfiguration configuration = this.loggingSystem.getLoggerConfiguration(name); return (configuration != null) ? new SingleLoggerLevels(configuration) : null; }
LoggersEndpoint定義了loggerLevels的read操作,它接受name,返回對(duì)應(yīng)的GroupLoggerLevels或者SingleLoggerLevels
configureLogLevel
@WriteOperation public void configureLogLevel(@Selector String name, @Nullable LogLevel configuredLevel) { Assert.notNull(name, "Name must not be empty"); LoggerGroup group = this.loggerGroups.get(name); if (group != null && group.hasMembers()) { group.configureLogLevel(configuredLevel, this.loggingSystem::setLogLevel); return; } this.loggingSystem.setLogLevel(name, configuredLevel); }
LoggersEndpoint定義了configureLogLevel這個(gè)write操作,它可用于變更logger的級(jí)別
小結(jié)
springboot的actuator定義了LoggersEndpoint,它定義了loggers的read操作,返回levels、loggers、groups;定義了loggerLevels的read操作,它接受name,返回對(duì)應(yīng)的GroupLoggerLevels或者SingleLoggerLevels;定義了configureLogLevel這個(gè)write操作,可用于變更logger的級(jí)別。
以上就是使用Spring Boot的LoggersEndpoint管理日志級(jí)別的詳細(xì)內(nèi)容,更多關(guān)于springboot LoggersEndpoint的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Java?多線(xiàn)程并發(fā)LockSupport
這篇文章主要介紹了Java?多線(xiàn)程并發(fā)LockSupport,LockSupport?類(lèi)是用于創(chuàng)建鎖和其他同步類(lèi)的基本線(xiàn)程阻塞原語(yǔ),更多相關(guān)內(nèi)容需要得小伙伴可以參考一下下面文章內(nèi)容2022-06-06有關(guān)IntelliJ IDEA中LeetCode插件配置問(wèn)題
這篇文章主要介紹了關(guān)于IntelliJ IDEA中LeetCode插件配置問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-08-08Java的Swing編程中使用SwingWorker線(xiàn)程模式及頂層容器
這篇文章主要介紹了在Java的Swing編程中使用SwingWorker線(xiàn)程模式及頂層容器的方法,適用于客戶(hù)端圖形化界面軟件的開(kāi)發(fā),需要的朋友可以參考下2016-01-01java實(shí)現(xiàn)隨機(jī)生成驗(yàn)證碼圖片
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)隨機(jī)生成驗(yàn)證碼圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-12-12MyBatis流式查詢(xún)的三種實(shí)現(xiàn)方法
流式查詢(xún)指的是查詢(xún)成功后不是返回一個(gè)集合而是返回一個(gè)迭代器,應(yīng)用每次從迭代器取一條查詢(xún)結(jié)果,本文介紹了MyBatis流式查詢(xún)的實(shí)現(xiàn),感興趣的可以了解一下2021-05-05