Changing logging levels at runtime
When a problem appears on a running server, the logs often have too little detail, and a restart to turn on more detailed logging can make the problem disappear. Mercury DB (HgDB) 3.0 lets a system administrator change logging levels without restarting the server: through a REST service and through a simple administration panel.
What you can do
- get the logging level of a category (a category is usually the name of a package or a class, e.g.,
org.mercury.lucene), - change the level of a category, e.g., turn on
DEBUGfor one package for the time of an analysis and return to the previous level afterwards, - search for categories by a part of the name (the result is limited to 30 categories, because there can be a very large number of them).
- The change applies only to the node that answered. In a cluster, repeat the operation on each node.
- The change is not saved in the configuration. After a restart of the node, the level from the logging configuration file applies again.
- Every change is written to the server log (level
WARN) together with the name of the user, the category and the levels before and after the change.
Required permissions
All operations require the system administrator role mrc-sysadmin. The role is one of the scopes defined for the OAuth clients (next to mrc-user and mrc-useradmin) and one of the roles of the user mapped in the role mapping table. There are two ways to reach the operations:
- the administration panel (a page in the browser): after logging in with a form, as for the page of case types in Swagger UI. The container allows only users with the role
mrc-sysadminto the page, and the role comes from the role mapping of the user, - the REST service with an OAuth token: the role is the
mrc-sysadminscope of the token.
The server determines the user and the roles from the session or from the token, and not from the context field of the request, so a request without the role is rejected with an error even when the client sends a context with any roles.
OAuth client configuration
The scope mrc-sysadmin must be allowed for the OAuth client for the path /rest/service/**. In the standard installation the configuration is in the file mercury-security-config-db-1.0.0.xml (directory classes/mercury-ws-app); in installations that keep it in the database, the same applies to the table MRC_LDAP_OAUTH_CONFIG. Example of an entry:
<item>
<appId>mercury-ws-app</appId>
<clientId>GIUPortalClient</clientId>
<contextPatern>/rest/service/**</contextPatern>
<scope>mrc-user,mrc-useradmin,mrc-sysadmin</scope>
...
</item>
The server accepts a token for a path when at least one scope of the token is also on the list of the entry. Without mrc-sysadmin in the entry, a token with only this scope is rejected with the invalid_scope error, while a token with mrc-user,mrc-sysadmin passes (the service still requires the role mrc-sysadmin). After changing the file, restart the application server.
Logging backend
The server logs through SLF4J. The service supports Logback, the logging backend of the server. For another backend (e.g., java.util.logging), the operations return an error with the name of the unsupported backend. The name of the used backend is returned in the backend field of the result.
REST service
The service is available at the address /rest/service/LoggerLevelsExtRest/{operation} and, like the other REST services of the system, requires an OAuth 2.0 token. The token request (POST /rest/token) must contain the scope parameter. The scopes can be separated by a space (as Swagger UI sends them, according to RFC 6749) or by a comma. The scopes must include mrc-sysadmin (e.g., scope=mrc-user,mrc-sysadmin) and have a common part with the scopes configured for the OAuth client for the /rest/service/** path, otherwise the server returns the invalid_scope error. All operations use the POST method, accept a JSON request and return a JSON envelope with the errorCode and errorMessage fields and the result data in the dto field. The field context of the request is optional.
getLevel
Gets the logging level of a category. A category that does not exist yet is not created: the result contains the level calculated from the parent categories (the level field is then null).
| Parameter | Description | Type | Required? |
|---|---|---|---|
| loggerName | Name of the category, e.g., org.mercury.lucene. The name ROOT denotes the root category. Allowed characters: letters, digits and . _ $ -, at most 256 characters. | String | Yes |
{
"loggerName": "org.mercury.lucene"
}
{
"errorCode": "",
"errorMessage": "",
"dto": {
"name": "org.mercury.lucene",
"level": null,
"effectiveLevel": "INFO",
"backend": "logback"
}
}
| Result field | Description |
|---|---|
| name | Name of the category |
| level | Level set directly on the category, or null when the category inherits the level |
| effectiveLevel | Effective level (set directly or inherited) |
| backend | Name of the logging backend (currently logback) |
setLevel
Changes the logging level of a category. A category that does not exist yet is created.
| Parameter | Description | Type | Required? |
|---|---|---|---|
| loggerName | Name of the category (as in getLevel) | String | Yes |
| level | New level: TRACE, DEBUG, INFO, WARN, ERROR, OFF or INHERIT. The level INHERIT removes the level set directly, so the category inherits it from the parent category (it does not apply to ROOT). The case of letters does not matter. | String | Yes |
{
"loggerName": "org.mercury.lucene",
"level": "DEBUG"
}
{
"errorCode": "",
"errorMessage": "",
"dto": {
"name": "org.mercury.lucene",
"level": "DEBUG",
"effectiveLevel": "DEBUG",
"backend": "logback",
"previousLevel": null
}
}
The previousLevel field contains the level set directly before the change (or null).
search
Searches for existing categories. The number of results is limited.
| Parameter | Description | Type | Required? |
|---|---|---|---|
| namePart | Part of the name of the category (case-insensitive). Empty means all categories. | String | No |
| onlyConfigured | Whether to return only categories with a level set directly. Default false. | Boolean | No |
| limit | The largest number of results. Default 20, at most 30. | Integer | No |
{
"namePart": "lucene",
"onlyConfigured": false,
"limit": 10
}
{
"errorCode": "",
"errorMessage": "",
"dto": {
"backend": "logback",
"limit": 10,
"truncated": false,
"loggers": [
{ "name": "org.mercury.lucene", "level": "DEBUG", "effectiveLevel": "DEBUG" },
{ "name": "org.mercury.lucene.query", "level": null, "effectiveLevel": "DEBUG" }
]
}
}
The truncated field has the value true when more categories match the criteria than the returned limit. In that case, narrow the search.
Administration panel
The server has a simple page for administrators. It is available at the address:
<address of the mercury-ws-app application>/static/admin/loggers.html
The page is protected in the same way as the page of case types in Swagger UI: when you open it without a session, the browser goes to the login form. After logging in, only a user with the role mrc-sysadmin gets access, and other users get the access denied (403) page. The page does not need an OAuth token or OAuth client data.
On the page you can:
- search for categories and change their levels directly in the table,
- get and change the level of a single category by its name (also a category that has not been created yet).
The page uses the session of the logged-in user, so after the session expires, refresh the page to log in again. It calls the same operations as the REST service, through the address <address of the application>/admin/loggers/{operation}, which is also available only for users with the role mrc-sysadmin.