下面列出了怎么用org.springframework.boot.actuate.logging.LoggersEndpoint的API类实例代码及写法,或者点击链接到github查看源代码。
private List<Map<String,?>> getLoggers() {
@SuppressWarnings({"unchecked", "raw"})
final Map<String,?> loggers = (Map) loggersEndpoint.loggers().get("loggers");
return loggers
.keySet()
.stream()
.map(key -> key.contains("$") ? null : new HashMap<String,Object>() {{
final LoggersEndpoint.SingleLoggerLevels logger = (LoggersEndpoint.SingleLoggerLevels) loggers.get(key);
put("name", key);
put("displayName", displayNameOf(key));
put("configuredLevel", logger.getConfiguredLevel());
put("effectiveLevel", logger.getEffectiveLevel());
}})
.filter(Objects::nonNull)
.collect(toList());
}
public ActuatorCommand(ApplicationContext applicationContext, Environment environment,
SshShellProperties properties, SshShellHelper helper,
@Lazy AuditEventsEndpoint audit, @Lazy BeansEndpoint beans,
@Lazy ConditionsReportEndpoint conditions,
@Lazy ConfigurationPropertiesReportEndpoint configprops, @Lazy EnvironmentEndpoint env,
@Lazy HealthEndpoint health,
@Lazy HttpTraceEndpoint httptrace, @Lazy InfoEndpoint info, @Lazy LoggersEndpoint loggers,
@Lazy MetricsEndpoint metrics,
@Lazy MappingsEndpoint mappings, @Lazy ScheduledTasksEndpoint scheduledtasks,
@Lazy ShutdownEndpoint shutdown,
@Lazy ThreadDumpEndpoint threaddump) {
this.applicationContext = applicationContext;
this.environment = environment;
this.properties = properties;
this.helper = helper;
this.audit = audit;
this.beans = beans;
this.conditions = conditions;
this.configprops = configprops;
this.env = env;
this.health = health;
this.httptrace = httptrace;
this.info = info;
this.loggers = loggers;
this.metrics = metrics;
this.mappings = mappings;
this.scheduledtasks = scheduledtasks;
this.shutdown = shutdown;
this.threaddump = threaddump;
}
/**
* Loggers method
*
* @param action action to make
* @param loggerName logger name for get or configure
* @param loggerLevel logger level for configure
* @return loggers
*/
@ShellMethod(key = "loggers", value = "Display or configure loggers.")
@ShellMethodAvailability("loggersAvailability")
public Object loggers(
@ShellOption(value = {"-a", "--action"}, help = "Action to perform", defaultValue = "list") LoggerAction action,
@ShellOption(value = {"-n", "--name"}, help = "Logger name for configuration or display", defaultValue =
ShellOption.NULL) String loggerName,
@ShellOption(value = {"-l", "--level"}, help = "Logger level for configuration", defaultValue =
ShellOption.NULL) LogLevel loggerLevel) {
if ((action == LoggerAction.get || action == LoggerAction.conf) && loggerName == null) {
throw new IllegalArgumentException("Logger name is mandatory for '" + action + "' action");
}
switch (action) {
case get:
LoggersEndpoint.LoggerLevels levels = loggers.loggerLevels(loggerName);
return "Logger named [" + loggerName + "] : [configured: " + levels.getConfiguredLevel() + "]";
case conf:
if (loggerLevel == null) {
throw new IllegalArgumentException("Logger level is mandatory for '" + action + "' action");
}
loggers.configureLogLevel(loggerName, loggerLevel);
return "Logger named [" + loggerName + "] now configured to level [" + loggerLevel + "]";
default:
// list
return loggers.loggers();
}
}
public LoggersHtmlEndpoint(final LoggersEndpoint loggersEndpoint,
final NavBar rightNavBar,
final EdisonApplicationProperties applicationProperties) {
this.loggersEndpoint = loggersEndpoint;
this.applicationProperties = applicationProperties;
rightNavBar.register(navBarItem(1, "Loggers", String.format("%s/loggers", applicationProperties.getManagement().getBasePath())));
}
@Bean
@ConditionalOnProperty(prefix = "edison.logging.ui", name = "enabled", matchIfMissing = true)
public LoggersHtmlEndpoint loggersHtmlEndpoint(final LoggersEndpoint loggersEndpoint,
final NavBar rightNavBar,
final EdisonApplicationProperties properties) {
return new LoggersHtmlEndpoint(loggersEndpoint, rightNavBar, properties);
}
@Bean
@ConditionalOnMissingBean
public ActuatorLoggersDimension createLoggersDimension(LoggersEndpoint endpoint) {
return new ActuatorLoggersDimension(endpoint);
}
public ActuatorLoggersDimension(LoggersEndpoint endpoint) {
this.endpoint = endpoint;
}
@Bean
public ActuatorLoggersDimension createLoggersDimension(LoggersEndpoint endpoint) {
return new ActuatorLoggersDimension(endpoint);
}
/**
* @return whether `loggers` command is available
*/
public Availability loggersAvailability() {
return availability("loggers", LoggersEndpoint.class);
}
LoggersCommand(@Value("${sshd.system.command.roles.loggers}") String[] systemRoles,
LoggersEndpoint loggersEndpoint) {
super(systemRoles);
this.loggersEndpoint = loggersEndpoint;
}