Skip to content

Commit b40fb7e

Browse files
committed
Support ansi colors and hyperlinks in logfile view
Everythind that looks like an http(s) url will be rendered as hyperlink and ansi-color escapes are now supported. In order to have ansi-colors in the file output you need to set a custom pattern. e.g.: logging.pattern.file="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx" closes codecentric#670
1 parent 0e7b618 commit b40fb7e

File tree

8 files changed

+46
-7
lines changed

8 files changed

+46
-7
lines changed

spring-boot-admin-docs/src/main/asciidoc/client.adoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ In case you are using the `spring-boot-admin-starter-client` it will be pulled i
4343
</dependency>
4444
----
4545

46+
[[logfile]]
47+
=== Logfile viewer ===
48+
49+
By default the logfile is not accessible via actuator endpoints and therefore not visible in Spring Boot Admin.
50+
In order to enable the logfile actuator endpoint you need to configure Spring Boot to write a logfile, either by setting
51+
`logging.path` or `logging.file`.
52+
53+
Spring Boot Admin will detect everything that looks like an URL and render it as hyperlink.
54+
55+
ANSI color-escapes are also supported. You need to set a custom file log pattern as Spring Boot's default one doesn't use colors.
56+
57+
.application.properties
58+
----
59+
logging.file=/var/log/sample-boot-application.log <1>
60+
logging.pattern.file=%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx <2>
61+
----
62+
<1> Destination the logfile is written to. Enables the logfile actuator endpoint.
63+
<2> File log pattern using ANSI colors.
64+
4665
[[spring-boot-admin-client]]
4766
=== Spring Boot Admin Client ===
4867

spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/resources/application.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
---
22
info:
33
scm-url: "@scm.url@"
4-
build-url: "http://travis-ci.org/@env.TRAVIS_REPO_SLUG@/builds/@env.TRxAVIS_BUILD_ID@"
4+
build-url: "http://travis-ci.org/@env.TRAVIS_REPO_SLUG@/builds/@env.TRAVIS_BUILD_ID@"
55

66
logging:
77
file: "target/boot-admin-sample-servlet.log"
8+
pattern:
9+
file: "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx"
810

911
management:
1012
endpoints:

spring-boot-admin-server-ui/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spring-boot-admin-server-ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@fortawesome/fontawesome-free-regular": "^5.0.13",
1515
"@fortawesome/fontawesome-free-solid": "^5.0.13",
1616
"@fortawesome/vue-fontawesome": "0.0.23",
17+
"ansi_up": "^3.0.0",
1718
"axios": "^0.18.0",
1819
"bulma": "^0.7.1",
1920
"bulma-badge": "^1.0.1",

spring-boot-admin-server-ui/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<configuration>
6464
<executable>npm</executable>
6565
<arguments>
66-
<argument>install</argument>
66+
<argument>ci</argument>
6767
</arguments>
6868
</configuration>
6969
</execution>

spring-boot-admin-server-ui/src/main/frontend/components/sba-formatted-obj.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
computed: {
3333
yaml() {
34-
return linkify(yaml.stringify(this.value, 2), 50);
34+
return linkify(yaml.stringify(this.value, 2), {maxLength: 50});
3535
}
3636
}
3737
}

spring-boot-admin-server-ui/src/main/frontend/utils/linkify.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ const shorten = (value, max) => {
4343
}
4444
};
4545

46-
export default (input, maxLength) => linkifyStr(input, {
46+
export default (input, options) => linkifyStr(input, {
4747
className: null,
4848
format(value, type) {
4949
if (type === 'url') {
50-
return shorten(value, maxLength || Number.MAX_VALUE);
50+
return shorten(value, options.maxLength || Number.MAX_VALUE);
5151
}
5252
return value;
53-
}
53+
},
54+
...options
5455
});

spring-boot-admin-server-ui/src/main/frontend/views/instances/logfile/index.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
<script>
4545
import subscribing from '@/mixins/subscribing';
4646
import Instance from '@/services/instance';
47+
import linkify from '@/utils/linkify';
4748
import {animationFrame, Observable} from '@/utils/rxjs';
49+
import AnsiUp from 'ansi_up';
4850
import _ from 'lodash';
4951
import prettyBytes from 'pretty-bytes';
5052
@@ -63,6 +65,9 @@
6365
atTop: false,
6466
skippedBytes: null
6567
}),
68+
created() {
69+
this.ansiUp = new AnsiUp();
70+
},
6671
mounted() {
6772
window.addEventListener('scroll', this.onScroll);
6873
},
@@ -84,7 +89,13 @@
8489
vm.hasLoaded = true;
8590
lines.forEach(line => {
8691
const child = document.createElement('pre');
87-
child.textContent = line;
92+
child.innerHTML = this.ansiUp.ansi_to_html(linkify(line, {
93+
validate: {
94+
url(value) {
95+
return /^(http|ftp)s?:\/\//.test(value);
96+
}
97+
}
98+
}));
8899
vm.$el.appendChild(child);
89100
});
90101

0 commit comments

Comments
 (0)