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,32 +34,67 @@ module.exports = function ($scope, application, ApplicationLogging) {
$scope.showPackageLoggers = !$scope.showPackageLoggers;
};
ApplicationLogging.getLoggingConfigurator(application).then(
function (logging) {
$scope.refreshLoggers = function (changedLogger) {
var outdatedLoggers = $scope.loggers.filter(function (logger) {
return !changedLogger || changedLogger.name === 'ROOT' || logger.name.indexOf(changedLogger.name) === 0;
});
logging.getLogLevels(outdatedLoggers).catch(function (responses) {
responses.some(function (response) {
if (response.error !== null) {
$scope.error = response;
return true;
}
return false;
});
});
};
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();
logging.getAllLoggers().then(function (loggers) {
$scope.loggers = loggers;
}).catch(function (response) {
$scope.error = response;
$scope.errorWhileListing = true;
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();
}
).catch(function (response) {
$scope.error = response;
$scope.errorWhileListing = true;
});
var initializeLoggersViaJolokia = function () {
ApplicationLogging.getLoggingConfigurator(application).then(
function (logging) {
$scope.refreshLoggers = function (changedLogger) {
var outdatedLoggers = $scope.loggers.filter(function (logger) {
return !changedLogger || changedLogger.name === 'ROOT' || logger.name.indexOf(changedLogger.name) === 0;
});
logging.getLogLevels(outdatedLoggers).catch(function (responses) {
responses.some(function (response) {
if (response.error !== null) {
$scope.error = response;
return true;
}
return false;
});
});
};
logging.getAllLoggers().then(function (loggers) {
$scope.loggers = loggers;
}).catch(function (response) {
$scope.error = response;
$scope.errorWhileListing = true;
});
}
).catch(function (response) {
$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.
......@@ -39,4 +40,4 @@
</tbody>
</table>
</div>
</div>
</div>
\ No newline at end of file
......@@ -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