Search code examples
javaspringspring-mvclogbackslf4j

File and logger was not created for slf4j


In my application i am using slf4j for logger. I have used logback.xml for configuration. While am running main class i am getting correct response, meaning for my testing purpose i write one main class. But same configuration after build and deploy i am not getting any response. Logger file also not created and log was not captured. Here i have mentioned my configuration xml file.

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <!-- Send debug messages to System.out -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- By default, encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
        </encoder>
    </appender>

    <!-- Send debug messages to a file at "c:/jcg.log" -->
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>d:/Logs/truprovider.log</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
        </encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <FileNamePattern>d:/Logs/truprovider.%i.log.zip</FileNamePattern>
            <MinIndex>1</MinIndex>
            <MaxIndex>10</MaxIndex>
        </rollingPolicy>

        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>10MB</MaxFileSize>
        </triggeringPolicy>
    </appender>

    <logger name="com.cts.emblem.batch" level="INFO" additivity="false">
            <appender-ref ref="STDOUT" />
            <appender-ref ref="FILE" />
    </logger>

    <!-- By default, the level of the root level is set to DEBUG -->
    <root level="INFO">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

Solution

  • I am getting default logger for my wildfly server. After modified the server configuration the problem will solved. Place the jboss-deployment-structure.xml file under META-INF.

    jboss-deployment-structure.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure>
      <deployment>
        <exclusions>
          <module name="org.apache.commons.logging" />
          <module name="org.apache.log4j" />
          <module name="org.jboss.logging" />
          <module name="org.jboss.logging.jul-to-slf4j-stub" />
          <module name="org.jboss.logmanager" />
          <module name="org.jboss.logmanager.log4j" />
          <module name="org.slf4j" />
          <module name="org.slf4j.impl" />
        </exclusions>
      </deployment>
    </jboss-deployment-structure>