1
 <?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="10 seconds">
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- Log message format -->
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>
  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <!-- Name of the file where the log messages are written -->
    <file>${IR_HOME}/ir_logs/ir_csp_management.log</file>
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <logger name="com.administration.csp" level="DEBUG" >
    <appender-ref ref="FILE" />
   </logger>
   <root>
    <appender-ref ref="STDOUT"/>
</root>
  <!-- Setting the root level of logging to INFO -->
  <root level="OFF">
    <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT" />
  </root>

  <appender name="FILE1" class="ch.qos.logback.core.FileAppender">
    <!-- Name of the file where the log messages are written -->
    <file>${IR_HOME}/ir_logs/ir_demoLog_management.log</file>
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <logger name="com.demo" level="DEBUG">
    <appender-ref ref="FILE1" />
   </logger>
  <!-- Setting the root level of logging to INFO -->
  <root level="info">
    <appender-ref ref="FILE" />
    <appender-ref ref="FILE1" />
  </root>
</configuration>

Only when Demo application with logger name="com.demo" runs , 2 files created having both logs of Demo Application.

I want only Demo application logs should be created not csp logs with logger name="com.administration.csp".

1 Answers1

0

1.Get Class name:

Use %class or %C in <pattern>

2. Condition checking in logback.xml.

Refer this official doc - Conditional processing of configuration files.

To do conditional checking in logback configuration, janino library should be added into your project.

<dependency>
  <groupId>org.codehaus.janino</groupId>
  <artifactId>janino</artifactId>
  <version>2.7.8</version>
</dependency>
Sundararaj Govindasamy
  • 8,180
  • 5
  • 44
  • 77
  • Tried to use in IF condition , error "The value of attribute "condition" associated with an element type "if" must not contain the '<' character". ${IR_HOME}/ir_logs/${LogFile} %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n – Preeti Garg Feb 23 '17 at 10:14