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 ...@@ -42,7 +42,8 @@ To interact with JMX-beans in the admin UI you have to include https://jolokia.o
[[loglevel-management]] [[loglevel-management]]
=== Loglevel managment === === 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] [source,xml]
.logback-spring.xml .logback-spring.xml
......
...@@ -15,12 +15,15 @@ ...@@ -15,12 +15,15 @@
*/ */
'use strict'; 'use strict';
var angular = require('angular');
module.exports = function ($scope, application, ApplicationLogging) { module.exports = function ($scope, application, ApplicationLogging) {
'ngInject'; 'ngInject';
$scope.loggers = []; $scope.loggers = [];
$scope.filteredLoggers = []; $scope.filteredLoggers = [];
$scope.limit = 10; $scope.limit = 10;
$scope.error = null;
$scope.showPackageLoggers = false; $scope.showPackageLoggers = false;
$scope.packageFilter = function (logger) { $scope.packageFilter = function (logger) {
...@@ -31,32 +34,67 @@ module.exports = function ($scope, application, ApplicationLogging) { ...@@ -31,32 +34,67 @@ module.exports = function ($scope, application, ApplicationLogging) {
$scope.showPackageLoggers = !$scope.showPackageLoggers; $scope.showPackageLoggers = !$scope.showPackageLoggers;
}; };
ApplicationLogging.getLoggingConfigurator(application).then( var Logger = function (name, data) {
function (logging) { this.name = name;
$scope.refreshLoggers = function (changedLogger) { this.level = data.configuredLevel || data.effectiveLevel;
var outdatedLoggers = $scope.loggers.filter(function (logger) { var i = name.lastIndexOf('.') + 1;
return !changedLogger || changedLogger.name === 'ROOT' || logger.name.indexOf(changedLogger.name) === 0; this.packageLogger = name.charAt(i) !== name.charAt(i).toUpperCase();
});
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) { this.setLevel = function (newLevel) {
$scope.loggers = loggers; return application.setLoggerLevel(name, newLevel);
}).catch(function (response) { };
$scope.error = response; };
$scope.errorWhileListing = true;
$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 class="container">
<div ng-if="errorWhileListing"> <div ng-if="errorWhileListing">
<p>To make the logging section work you need to make the /jolokia-endpoint accessible. <p><b>This only applies to Spring Boot 1.4.x and older applications:</b>
<br/> Include the jolokia-core.jar in your spring-boot-application: <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> <pre>&lt;dependency&gt; &lt;groupId>org.jolokia&lt;/groupId&gt; &lt;artifactId>jolokia-core&lt;/artifactId&gt; &lt;/dependency&gt;</pre>
</p> </p>
<p>Please note that the logging section currently only works with Logback. <p>Please note that the logging section currently only works with Logback.
...@@ -39,4 +40,4 @@ ...@@ -39,4 +40,4 @@
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
\ No newline at end of file
...@@ -18,17 +18,13 @@ ...@@ -18,17 +18,13 @@
module.exports = function ($resource, $http) { module.exports = function ($resource, $http) {
'ngInject'; 'ngInject';
var Application = $resource('api/applications/:id', { var Application = $resource('api/applications/:id', { id: '@id' }, {
id: '@id'
}, {
query: { query: {
method: 'GET', method: 'GET',
isArray: true isArray: true
}, }, get: {
get: {
method: 'GET' method: 'GET'
}, }, remove: {
remove: {
method: 'DELETE' method: 'DELETE'
} }
}); });
...@@ -57,14 +53,11 @@ module.exports = function ($resource, $http) { ...@@ -57,14 +53,11 @@ module.exports = function ($resource, $http) {
}; };
Application.prototype.getEnv = function (key) { Application.prototype.getEnv = function (key) {
return $http.get('api/applications/' + this.id + '/env' + (key ? '/' + key : '')).then( return $http.get('api/applications/' + this.id + '/env' + (key ? '/' + key : '')).then(convert);
convert);
}; };
Application.prototype.setEnv = function (map) { Application.prototype.setEnv = function (map) {
return $http.post('api/applications/' + this.id + '/env', '', { return $http.post('api/applications/' + this.id + '/env', '', { params: map }).then(convert);
params: map
}).then(convert);
}; };
Application.prototype.resetEnv = function () { Application.prototype.resetEnv = function () {
...@@ -83,5 +76,13 @@ module.exports = function ($resource, $http) { ...@@ -83,5 +76,13 @@ module.exports = function ($resource, $http) {
return $http.get('api/applications/' + this.id + '/trace').then(convertArray); 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; return Application;
}; };
\ No newline at end of file
...@@ -69,7 +69,7 @@ public class AdminServerProperties { ...@@ -69,7 +69,7 @@ public class AdminServerProperties {
* Endpoints to be proxified by spring boot admin. * Endpoints to be proxified by spring boot admin.
*/ */
private String[] endpoints = { "env", "metrics", "trace", "dump", "jolokia", "info", 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() { public String[] getEndpoints() {
return endpoints; 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