Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2502

Support ContextListener like in Logback

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not A Problem
    • 2.11.1
    • None
    • Web/Servlet
    • None

    Description

      Hi,

      i'm trying to switch to Log4j from Logback.

      In the configuration (the file appender), i'm using a system property that does not exist and is created in the contextListener (the logs path is generated at runtime and can't be set staticly in the config file)

      <configuration debug="true">
      
       <contextListener class="it.my.LoggerStartupListener"/>
      
       <appender name="JSON" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_PATH}/app.log</File>
       <FileNamePattern>${LOG_PATH}/app.%d{yyyy-MM-dd}.%i.log.gz
       </FileNamePattern>
      ...
      public class LoggerStartupListener extends ContextAwareBase implements LoggerContextListener, LifeCycle {
      
       private static final String LOG_PATH = "LOG_PATH";
      
       @Override
       public void start() {
          getContext().putProperty(LOG_PATH, Paths.get(OSUtils.getBasePath(), "logs").toString());
        }
      }

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            lelmarir Michele Preti
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: