Configuring Logging for Applications

Last updated 2 minutes ago

Learn how to configure logging for CoreMedia Applications

LightbulbWhat you'll learn

  • Set an application property for the log level
  • Change the log level during runtime with an actuator

Person reading a bookPrerequisites

  • A CoreMedia system

WristwatchTime matters

Reading time: 3 to 5 minutes

Person in front of a laptopShould I read this?

This guide is for Developers, Administrators.

CoreMedia applications use Logback. The log configuration for each application is packaged into each application JAR archive.

Configuring Logging at Buildtime

To configure the log level of a specific logger, you only need to set an application property, which follows the Spring Boot standard for log configuration. You can set the property in any of the location described at https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config

If for example you want to set the log level of the com.coremedia logger to debug, set the following property and restart the application.

logging.level.com.coremedia=debug

Configuring Logging at Runtime

If you want to change the log level of a logger at runtime without a restart, you can use the logger management actuator for an application.

Prerequisites

  • The endpoint must be accessible via the actuator, defined via management.endpoints.web.exposure.include. By default, the property is set to "*" in the development environment.

  • The logger’s endpoint must be enabled via the property management.endpoint.loggers.enabled. By default, the property is set to "true".

If that is the case, you can use a simple PUT request to set the new level. Replace <LEVEL>, <HOST>, <PORT> and <LOGGER> with the respective values.

curl -s -X POST -H "Content-Type: application/json" -d "{\"configuredLevel\": \"<LEVEL>\"}" <HOST>:<PORT>/loggers/<LOGGER>

Please refer to the official Spring documentation for more details.

If you want to change other logging characteristics, you need to modify the src/main/resources/logback-spring.xml file in each Spring Boot application module before building it.

Copyright © 2021 CoreMedia GmbH, CoreMedia Corporation. All Rights Reserved.