diff --git a/CHANGELOG.md b/CHANGELOG.md index 1702546..ed1a1b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # spring-boot-actuator-logview changelog +## 0.2.9 +- Add configuration option to override stylesheet urls (fixes [#20](https://github.com/lukashinsch/spring-boot-actuator-logview/issues/20)) + ## 0.2.8 - Remove tail option for files inside archives in UI (lead to 500 error before) (fixes [#17](https://github.com/lukashinsch/spring-boot-actuator-logview/issues/17)) diff --git a/README.md b/README.md index 99f4d5f..b10ebc9 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,10 @@ Simple logfile viewer as spring boot actuator endpoint ##Howto use * include library on classpath of spring-boot app -* configure logging.path in spring environment -(alternatively - when using custom logging configuration or logging.file - use endpoints.logview.path) +* configure `logging.path` in spring environment +(alternatively - when using custom logging configuration or `logging.file - use `endpoints.logview.path) * endpoint will be available under /log +* to replace default stylesheet links, set property `endpoints.logview.stylesheets` in yml to list of urls ###Gradle ```groovy diff --git a/lib/src/main/java/eu/hinsch/spring/boot/actuator/logview/LogViewEndpoint.java b/lib/src/main/java/eu/hinsch/spring/boot/actuator/logview/LogViewEndpoint.java index 60782fe..cd07340 100644 --- a/lib/src/main/java/eu/hinsch/spring/boot/actuator/logview/LogViewEndpoint.java +++ b/lib/src/main/java/eu/hinsch/spring/boot/actuator/logview/LogViewEndpoint.java @@ -3,7 +3,6 @@ import freemarker.template.Configuration; import freemarker.template.TemplateException; import org.apache.commons.io.IOUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.endpoint.Endpoint; import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint; import org.springframework.ui.Model; @@ -34,13 +33,14 @@ */ public class LogViewEndpoint implements MvcEndpoint{ - private static List fileProviders; + private final List fileProviders; private final Configuration freemarkerConfig; - private String loggingPath; + private final String loggingPath; + private final List stylesheets; - @Autowired - public LogViewEndpoint(String loggingPath) { + public LogViewEndpoint(String loggingPath, List stylesheets) { this.loggingPath = loggingPath; + this.stylesheets = stylesheets; fileProviders = asList(new FileSystemFileProvider(), new ZipArchiveFileProvider(), new TarGzArchiveFileProvider()); @@ -72,6 +72,7 @@ public String list(Model model, // TODO model should no longer be injected model.addAttribute("currentFolder", currentFolder.toAbsolutePath().toString()); model.addAttribute("base", base != null ? URLEncoder.encode(base, "UTF-8") : ""); model.addAttribute("parent", getParent(currentFolder)); + model.addAttribute("stylesheets", stylesheets); return FreeMarkerTemplateUtils.processTemplateIntoString(freemarkerConfig.getTemplate("logview.ftl"), model); } diff --git a/lib/src/main/java/eu/hinsch/spring/boot/actuator/logview/LogViewEndpointAutoconfig.java b/lib/src/main/java/eu/hinsch/spring/boot/actuator/logview/LogViewEndpointAutoconfig.java index 34080ab..220c1c1 100644 --- a/lib/src/main/java/eu/hinsch/spring/boot/actuator/logview/LogViewEndpointAutoconfig.java +++ b/lib/src/main/java/eu/hinsch/spring/boot/actuator/logview/LogViewEndpointAutoconfig.java @@ -1,9 +1,15 @@ package eu.hinsch.spring.boot.actuator.logview; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +import java.util.List; + +import static java.util.Arrays.asList; @Configuration public class LogViewEndpointAutoconfig { @@ -13,13 +19,37 @@ public class LogViewEndpointAutoconfig { @ConditionalOnProperty(LOGGING_PATH) @Bean - public LogViewEndpoint logViewEndpointWithDefaultPath(Environment environment) { - return new LogViewEndpoint(environment.getRequiredProperty(LOGGING_PATH)); + public LogViewEndpoint logViewEndpointWithDefaultPath(Environment environment, EndpointConfiguration configuration) { + return new LogViewEndpoint(environment.getRequiredProperty(LOGGING_PATH), configuration.getStylesheets()); } @ConditionalOnProperty(ENDPOINTS_LOGVIEW_PATH) @Bean - public LogViewEndpoint logViewEndpointWithDeviatingPath(Environment environment) { - return new LogViewEndpoint(environment.getRequiredProperty(ENDPOINTS_LOGVIEW_PATH)); + public LogViewEndpoint logViewEndpointWithDeviatingPath(Environment environment, EndpointConfiguration configuration) { + return new LogViewEndpoint(configuration.getPath(), configuration.getStylesheets()); + } + + @Component + @ConfigurationProperties(prefix = "endpoints.logview") + static class EndpointConfiguration { + private List stylesheets = asList("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css", + "https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"); + private String path; + + public List getStylesheets() { + return stylesheets; + } + + public void setStylesheets(List stylesheets) { + this.stylesheets = stylesheets; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } } } diff --git a/lib/src/main/resources/META-INF/spring-configuration-metadata.json b/lib/src/main/resources/META-INF/spring-configuration-metadata.json index d7e9db0..3e3a02e 100644 --- a/lib/src/main/resources/META-INF/spring-configuration-metadata.json +++ b/lib/src/main/resources/META-INF/spring-configuration-metadata.json @@ -4,5 +4,9 @@ "type": "java.lang.String", "description": "Logfile root folder - if logging.path is not used", "sourceType": "eu.hinsch.spring.boot.actuator.logview.LogViewEndpointAutoconfig" + }, + { + "name": "endpoints.logview.stylesheets", + "description": "Stylesheets urls to load (will replace default CDN links)" } ]} \ No newline at end of file diff --git a/lib/src/main/resources/templates/logview.ftl b/lib/src/main/resources/templates/logview.ftl index c946f08..bf2e624 100644 --- a/lib/src/main/resources/templates/logview.ftl +++ b/lib/src/main/resources/templates/logview.ftl @@ -1,8 +1,9 @@ Logfiles - - + <#list stylesheets as stylesheet> + +