title: Separation of Spring logs and User - defined logs
body: <p>I am building a Spring boot project with Tomcat server where in Spring automatically takes care of all the logging mechanism, all the logs are present in "catalina.out" file.</p>
  
  <p>Now that, I have a requirement where I need to log only specific information to a separate log file.</p>
  
  <p>I have done the below configuration, but now all the logs including the main logs are appending in the same file.</p>
  
  <p>I need only specific logs into a separate log file.</p>
  
  <p>Can anyone suggest me a solution for this?</p>
  
  <p>My pom.xml looks like this.</p>
  
  <pre><code> &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&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;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-log4j&lt;/artifactId&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>My log4j.properties look like this.</p>
  
  <pre><code># Root logger option
  log4j.rootLogger=INFO,file
  
  # Direct log messages to a log file
  log4j.appender.file=org.apache.log4j.RollingFileAppender
  
  #Redirect to Tomcat logs folder
  #log4j.appender.file.File=${catalina.home}/logs/logging.log
  
  log4j.appender.file.File=/my_log.log
  log4j.appender.file.Append=true
  log4j.appender.file.MaxFileSize=10MB
  log4j.appender.file.MaxBackupIndex=10
  log4j.appender.file.layout=org.apache.log4j.PatternLayout
  log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
  </code></pre>
  
  <p>The java file looks like this.</p>
  
  <pre><code>static org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(MyClass.class.getName());
  
  log4jLogger.info("My specific logs here");
  </code></pre>