Class LogbackInitializer

  • All Implemented Interfaces:
    java.util.EventListener, org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>

    @Order(-2147483638)
    public class LogbackInitializer
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      LogbackInitializer()
      Default constructor, called by Spring.
      LogbackInitializer​(java.lang.String logbackConfigFileName)
      Creates a logback intiializer that looks for a logback configuration file with the specified file name inside the application home directory.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.nio.file.Path getAdditionalLogbackConfigurationFile​(au.net.causal.shoelaces.apphome.ApplicationHome applicationHome)
      Finds the logback configuration file under the application home directory.
      void onApplicationEvent​(org.springframework.context.ApplicationEvent event)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LogbackInitializer

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

        public LogbackInitializer​(java.lang.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 Detail

      • onApplicationEvent

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

        protected java.nio.file.Path getAdditionalLogbackConfigurationFile​(au.net.causal.shoelaces.apphome.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.