Commit d6cb259c by Johannes Edmeier

Use the loggers endpoint from boot 1.5.x

Add support for the /loggers endpoint from spring boot 1.5.x. With this change log4j2 (and every other logging backend supported by spring boot) is supported in the logging view. The old implementation will be kept a while, so that the clients aren't forced to migrate. closes #305
parent 79c236c0
......@@ -42,7 +42,8 @@ To interact with JMX-beans in the admin UI you have to include https://jolokia.o
[[loglevel-management]]
=== Loglevel managment ===
Currently the loglevel management is only available for http://logback.qos.ch/[Logback]. It is accessed via JMX so <<jmx-bean-management, include Jolokia>> in your application. In addition you have configure Logback's `JMXConfigurator`:
For applications using Spring Boot 1.5.x (or later) you can manage loglevels out-of-the-box.
For applications using older versions of Spring Boot the loglevel management is only available for http://logback.qos.ch/[Logback]. It is accessed via JMX so <<jmx-bean-management, include Jolokia>> in your application. In addition you have configure Logback's `JMXConfigurator`:
[source,xml]
.logback-spring.xml
......
......@@ -15,12 +15,15 @@
*/
'use strict';
var angular = require('angular');
module.exports = function ($scope, application, ApplicationLogging) {
'ngInject';
$scope.loggers = [];
$scope.filteredLoggers = [];
$scope.limit = 10;
$scope.error = null;
$scope.showPackageLoggers = false;
$scope.packageFilter = function (logger) {
......@@ -31,6 +34,39 @@ module.exports = function ($scope, application, ApplicationLogging) {
$scope.showPackageLoggers = !$scope.showPackageLoggers;
};
var Logger = function (name, data) {
this.name = name;
this.level = data.configuredLevel || data.effectiveLevel;
var i = name.lastIndexOf('.') + 1;
this.packageLogger = name.charAt(i) !== name.charAt(i).toUpperCase();
this.setLevel = function (newLevel) {
return application.setLoggerLevel(name, newLevel);
};
};
$scope.refreshLoggers = function () {
return application.getLoggers().then(function (response) {
$scope.error = null;
var loggers = [];
angular.forEach(response.data, function (value, key) {
loggers.push(new Logger(key, value));
});
$scope.loggers = loggers;
}).catch(function (response) {
$scope.error = response;
});
};
$scope.refreshLoggers().then(function () {
if ($scope.error != null && $scope.error.status === 404) {
//in case the client is a boot 1.4 application use the old jolokia style.
$scope.error = null;
initializeLoggersViaJolokia();
}
});
var initializeLoggersViaJolokia = function () {
ApplicationLogging.getLoggingConfigurator(application).then(
function (logging) {
$scope.refreshLoggers = function (changedLogger) {
......@@ -59,4 +95,6 @@ module.exports = function ($scope, application, ApplicationLogging) {
$scope.error = response;
$scope.errorWhileListing = true;
});
};
};
<div class="container">
<div ng-if="errorWhileListing">
<p>To make the logging section work you need to make the /jolokia-endpoint accessible.
<br/> Include the jolokia-core.jar in your spring-boot-application:
<p><b>This only applies to Spring Boot 1.4.x and older applications:</b>
<br/> To make the logging section work you need to make the /jolokia-endpoint accessible.
<br/>Include the jolokia-core.jar in your spring-boot-application:
<pre>&lt;dependency&gt; &lt;groupId>org.jolokia&lt;/groupId&gt; &lt;artifactId>jolokia-core&lt;/artifactId&gt; &lt;/dependency&gt;</pre>
</p>
<p>Please note that the logging section currently only works with Logback.
......
......@@ -18,17 +18,13 @@
module.exports = function ($resource, $http) {
'ngInject';
var Application = $resource('api/applications/:id', {
id: '@id'
}, {
var Application = $resource('api/applications/:id', { id: '@id' }, {
query: {
method: 'GET',
isArray: true
},
get: {
}, get: {
method: 'GET'
},
remove: {
}, remove: {
method: 'DELETE'
}
});
......@@ -57,14 +53,11 @@ module.exports = function ($resource, $http) {
};
Application.prototype.getEnv = function (key) {
return $http.get('api/applications/' + this.id + '/env' + (key ? '/' + key : '')).then(
convert);
return $http.get('api/applications/' + this.id + '/env' + (key ? '/' + key : '')).then(convert);
};
Application.prototype.setEnv = function (map) {
return $http.post('api/applications/' + this.id + '/env', '', {
params: map
}).then(convert);
return $http.post('api/applications/' + this.id + '/env', '', { params: map }).then(convert);
};
Application.prototype.resetEnv = function () {
......@@ -83,5 +76,13 @@ module.exports = function ($resource, $http) {
return $http.get('api/applications/' + this.id + '/trace').then(convertArray);
};
Application.prototype.getLoggers = function () {
return $http.get('api/applications/' + this.id + '/loggers').then(convertArray);
};
Application.prototype.setLoggerLevel = function (logger, level) {
return $http.post('api/applications/' + this.id + '/loggers/' + logger, { configuredLevel: level });
};
return Application;
};
\ No newline at end of file
......@@ -69,7 +69,7 @@ public class AdminServerProperties {
* Endpoints to be proxified by spring boot admin.
*/
private String[] endpoints = { "env", "metrics", "trace", "dump", "jolokia", "info",
"trace", "logfile", "refresh", "flyway", "liquibase", "heapdump" };
"trace", "logfile", "refresh", "flyway", "liquibase", "heapdump", "loggers" };
public String[] getEndpoints() {
return endpoints;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment