Class LogbackInitializer

java.lang.Object
au.net.causal.shoelaces.logconfig.LogbackInitializer
All Implemented Interfaces:
EventListener, org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>

@Order(-2147483638) public class LogbackInitializer extends Object implements org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
Configures Logback logging if a logback configuration file exists in the application home directory.

This initializer is called early when the Spring application is initialized. If the logging.config property isn't set (which would indicate the user wishes to use a custom logging configuration file), the application home directory (see the application home Shoelaces module documentation for more info on this) is searched for a logback configuration file, and if it exists then the logging.config property is set to the location of this file. This allows users of a Spring Boot application that uses this module to easily configure logging by adding a logging configuration file in a known place.

This initializer is registered with Spring using spring.factories so it is loaded at startup. If you wish to subclass and override some of this logic, you will need to also register your subclass using spring.factories and ensure that your initializer has an order (using the @Order annotation) that makes it run before this one.

  • Constructor Details

    • LogbackInitializer

      public LogbackInitializer()
      Default constructor, called by Spring.
    • LogbackInitializer

      public LogbackInitializer(String logbackConfigFileName)
      Creates a logback intiializer that looks for a logback configuration file with the specified file name inside the application home directory.
      Parameters:
      logbackConfigFileName - logback configuration file name to look for under application home.
  • Method Details

    • onApplicationEvent

      public void onApplicationEvent(org.springframework.context.ApplicationEvent event)
      Specified by:
      onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
    • getAdditionalLogbackConfigurationFile

      protected Path getAdditionalLogbackConfigurationFile(ApplicationHome applicationHome)
      Finds the logback configuration file under the application home directory.
      Parameters:
      applicationHome - the application home.
      Returns:
      the logback configuration file, or null if it does not exist.