Skip to content

Commit

Permalink
Merge pull request #21 from lukashinsch/configure-style-urls
Browse files Browse the repository at this point in the history
Add config option to override stylesheet links
  • Loading branch information
lukashinsch committed Apr 12, 2016
2 parents 7db35d3 + b00248d commit 04dcc5e
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <management-base>/log
* to replace default stylesheet links, set property `endpoints.logview.stylesheets` in yml to list of urls

###Gradle
```groovy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,13 +33,14 @@
*/
public class LogViewEndpoint implements MvcEndpoint{

private static List<FileProvider> fileProviders;
private final List<FileProvider> fileProviders;
private final Configuration freemarkerConfig;
private String loggingPath;
private final String loggingPath;
private final List<String> stylesheets;

@Autowired
public LogViewEndpoint(String loggingPath) {
public LogViewEndpoint(String loggingPath, List<String> stylesheets) {
this.loggingPath = loggingPath;
this.stylesheets = stylesheets;
fileProviders = asList(new FileSystemFileProvider(),
new ZipArchiveFileProvider(),
new TarGzArchiveFileProvider());
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<String> 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<String> getStylesheets() {
return stylesheets;
}

public void setStylesheets(List<String> stylesheets) {
this.stylesheets = stylesheets;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
]}
5 changes: 3 additions & 2 deletions lib/src/main/resources/templates/logview.ftl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<html>
<head>
<title>Logfiles</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"/>
<#list stylesheets as stylesheet>
<link rel="stylesheet" href="${stylesheet}">
</#list>
<style>
.form-group {
margin-right: 10px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ public class LogViewEndpointAutoconfigTest {
@Mock
private Environment environment;

@Mock
private LogViewEndpointAutoconfig.EndpointConfiguration configuration;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}

@Test
public void shouldCreateBeanForDefaultPath() {
assertThat(new LogViewEndpointAutoconfig().logViewEndpointWithDefaultPath(environment), notNullValue());
assertThat(new LogViewEndpointAutoconfig().logViewEndpointWithDefaultPath(environment, configuration), notNullValue());
}

@Test
public void shouldCreateBeanForDeviatingPath() {
assertThat(new LogViewEndpointAutoconfig().logViewEndpointWithDeviatingPath(environment), notNullValue());
assertThat(new LogViewEndpointAutoconfig().logViewEndpointWithDeviatingPath(environment, configuration), notNullValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public class LogViewEndpointTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
logViewEndpoint = new LogViewEndpoint(temporaryFolder.getRoot().getAbsolutePath());
logViewEndpoint = new LogViewEndpoint(temporaryFolder.getRoot().getAbsolutePath(),
new LogViewEndpointAutoconfig.EndpointConfiguration().getStylesheets());
model = new ExtendedModelMap();
now = new Date().getTime();
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/application.properties

This file was deleted.

11 changes: 11 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
management:
context-path: /manage
logging:
path: /tmp/log

#endpoints:
# logview:
# stylesheets:
# - http://foo.bar
# - http://bar.foo
# path: /tmp/log

0 comments on commit 04dcc5e

Please sign in to comment.