title: Configuring log4j2.properties in Spring Boot
body: <p>I am a newbie to Spring Boot. I have a running Spring Boot project. I want to use log4j2 (I am bound to use log4j2 itself because of project restrictions) to redirect all logs of different levels to a log file named 'test.log'</p>
  
  <p><strong><em>Problem is - despite of all proper code included, I am not able to log INFO level logs in my test.log</em></strong> (I want to obviously log error and debug level logs also, but at least first INFO level logs should work fine)</p>
  
  <p>--- I have excluded default logging and included log4j2 dependency in pom.xml :</p>
  
  <pre><code>&lt;!-- Exclude Spring Boot's Default Logging --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                      &lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Add Log4j2 Dependency --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
              &lt;version&gt;2.10.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
              &lt;version&gt;2.10.0&lt;/version&gt;
          &lt;/dependency&gt; 
  </code></pre>
  
  <p>--- I have included logging.config in application.properties:</p>
  
  <pre><code>logging.file=logs/test.log
  logging.level.*=INFO
  logging.config=src/main/resources/log4j2.properties
  </code></pre>
  
  <p>--- My <code>log4j2.properties</code> looks as follows:</p>
  
  <pre><code>#status = error // do i need this actually??
  dest = logs/test.log
  name = PropertiesConfig
  
  property.filename = logs/test.log
  
  appender.console.type = Console
  appender.console.name = STDOUT
  appender.console.layout.type = PatternLayout
  appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
  
  appender.rolling.type = RollingFile
  appender.rolling.name = RollingFile
  appender.rolling.fileName = logs/test.log
  appender.rolling.filePattern = logs/test1-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
  appender.rolling.layout.type = PatternLayout
  appender.rolling.layout.pattern = %d %-5p %-17c{2} (%30F:%L) %3x - %m%n
  appender.rolling.policies.type = Policies
  appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
  appender.rolling.policies.time.interval = 2
  appender.rolling.policies.time.modulate = true
  appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
  appender.rolling.policies.size.size=10MB
  appender.rolling.strategy.type = DefaultRolloverStrategy
  appender.rolling.strategy.max = 5
  
  logger.rolling.name = com.thp.clinic.allergiesConditions
  logger.rolling.level = info
  logger.rolling.additivity = false
  logger.rolling.appenderRef.rolling.ref = RollingFile
  #rootCategory=INFO,rolling,stdout
  #logging.level.root=info
  
  #rootLogger.level = debug  //do i necessarily need root Logger????
  #rootLogger.appenderRefs = RollingFile
  #rootLogger.appenderRef.stdout.ref = STDOUT
  
  logger.rolling.name=org.hibernate.SQL
  logger.rolling.level = debug
  </code></pre>
  
  <p>--- Also controller of my test API has following test log lines:</p>
  
  <pre><code>    //Logger logger = LogManager.getLogger //is included       
  logger.debug("This is a debug message");
  logger.info("This is an info message");
  logger.warn("This is a warn message");
  logger.error("This is an error message");
  logger.fatal("This is a fatal message");
  </code></pre>
  
  <p>--- In my understanding, I have included all required things in code. But I am facing this issues - <strong><em>when I hit API, only hibernate debug loggers are being added to test.log; The five test loggers(or even other info level logs used) i have included in controller are not getting logged in test.log;</em></strong></p>
  
  <p>The console looks like following(two of five loggers are being displayed on console, but here also INFO level logger is missing):</p>
  
  <pre><code>20:05:42.989 [http-nio-8000-exec-1] ERROR com.test.app.appController - This is an error message
  20:05:42.994 [http-nio-8000-exec-1] FATAL com.test.app.appController - This is a fatal message
  Hibernate: //used hibernate queries are displayed to console as needed
  </code></pre>
  
  <blockquote>
    <p>It would be great help if someone can point out what i need to change
    in the code. Because of improper understanding of log4j2, i guess
    something needs to change in log4j2.properties</p>
  </blockquote>
  
  <p>Please help!!
  Thanks in advance</p>