org.springframework.boot.context.logging

Class LoggingApplicationListener

  • java.lang.Object
    • org.springframework.boot.context.logging.LoggingApplicationListener
  • All Implemented Interfaces:
    EventListener, ApplicationListener<ApplicationEvent>, GenericApplicationListener, Ordered


    public class LoggingApplicationListener
    extends Object
    implements GenericApplicationListener
    An ApplicationListener that configures the LoggingSystem. If the environment contains a logging.config property it will be used to bootstrap the logging system, otherwise a default configuration is used. Regardless, logging levels will be customized if the environment contains logging.level.* entries.

    Debug and trace logging for Spring, Tomcat, Jetty and Hibernate will be enabled when the environment contains debug or trace properties that aren't set to "false" (i.e. if you start your application using java -jar myapp.jar [--debug | --trace]). If you prefer to ignore these properties you can set parseArgs to false.

    By default, log output is only written to the console. If a log file is required the logging.path and logging.file properties can be used.

    Some system properties may be set as side effects, and these can be useful if the logging configuration supports placeholders (i.e. log4j or logback):

    • LOG_FILE is set to the value of path of the log file that should be written (if any).
    • PID is set to the value of the current process ID if it can be determined.
    Since:
    2.0.0
    Author:
    Dave Syer, Phillip Webb, Andy Wilkinson, Madhura Bhave
    See Also:
    LoggingSystem.get(ClassLoader)
    • Field Detail

      • DEFAULT_ORDER

        public static final int DEFAULT_ORDER
        The default order for the LoggingApplicationListener.
        See Also:
        Constant Field Values
      • CONFIG_PROPERTY

        public static final String CONFIG_PROPERTY
        The name of the Spring property that contains a reference to the logging configuration to load.
        See Also:
        Constant Field Values
    • Constructor Detail

      • LoggingApplicationListener

        public LoggingApplicationListener()
    • Method Detail

      • initialize

        protected void initialize(ConfigurableEnvironment environment,
                                  ClassLoader classLoader)
        Initialize the logging system according to preferences expressed through the Environment and the classpath.
        Parameters:
        environment - the environment
        classLoader - the classloader
      • setOrder

        public void setOrder(int order)
      • getOrder

        public int getOrder()
        Specified by:
        getOrder in interface Ordered
      • setSpringBootLogging

        public void setSpringBootLogging(LogLevel springBootLogging)
        Sets a custom logging level to be used for Spring Boot and related libraries.
        Parameters:
        springBootLogging - the logging level
      • setParseArgs

        public void setParseArgs(boolean parseArgs)
        Sets if initialization arguments should be parsed for --debug and --trace options. Defaults to true.
        Parameters:
        parseArgs - if arguments should be parsed