DBILITY

logback에서 springframework log가 출력되지 않을때 본문

java/spring

logback에서 springframework log가 출력되지 않을때

DBILITY 2016. 10. 21. 21:39
반응형

springframework은 jakarta commons logging을 사용하므로, commons-logging의 dependancy를 제거(exclude)하고,

slf4j-api dependancy 확인 후 jcl-over-slf4j dependancy를 추가한다( slf4j Bridging legacy APIs 참조 )

 

  1. spring mvc pom sample
    	<properties>
    		<java-version>1.6</java-version>
    		<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
    		<org.aspectj-version>1.6.10</org.aspectj-version>
    		<org.slf4j-version>1.6.6</org.slf4j-version>
    		<cglib-verion>2.2</cglib-verion>
    	</properties>
    	<dependencies>
    		<!-- Spring -->
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-context</artifactId>
    			<version>${org.springframework-version}</version>
    			<exclusions>
    				<!-- Exclude Commons Logging in favor of SLF4j -->
    				<exclusion>
    					<groupId>commons-logging</groupId>
    					<artifactId>commons-logging</artifactId>
    				 </exclusion>
    			</exclusions>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-webmvc</artifactId>
    			<version>${org.springframework-version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-tx</artifactId>
    			<version>${org.springframework-version}</version>
    		</dependency>		
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-jdbc</artifactId>
    			<version>${org.springframework-version}</version>
    		</dependency>
    
    		<!-- Logging -->
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>slf4j-api</artifactId>
    			<version>${org.slf4j-version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>jcl-over-slf4j</artifactId>
    			<version>${org.slf4j-version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>log4j-over-slf4j</artifactId>
    			<version>${org.slf4j-version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.lazyluke</groupId>
    			<artifactId>log4jdbc-remix</artifactId>
    			<version>0.2.7</version>
    			<exclusions>
    				<exclusion>
    					<artifactId>slf4j-api</artifactId>
    					<groupId>org.slf4j</groupId>
    				</exclusion>
    			</exclusions>
    		</dependency>
    		<dependency>
    			<groupId>ch.qos.logback</groupId>
    			<artifactId>logback-classic</artifactId>
    			<version>1.0.9</version>
    			<exclusions>
    				<exclusion>
    					<artifactId>slf4j-api</artifactId>
    					<groupId>org.slf4j</groupId>
    				</exclusion>
    			</exclusions>
    		</dependency>
    	</dependencies>
  2. logback.xml sample
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    
    	<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
    		<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder
    			by default -->
    		<encoder>
    			<!-- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> -->
    			<!-- <pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern> -->
    			<!-- <pattern>%d{HH:mm:ss.SSS} [%thread] %-7level %50.50logger{36} %4.4L - %msg%n</pattern> -->
    			<!-- <pattern>%d{HH:mm:ss.SSS} %-5level %40.40logger{36} %4.4L - %msg%n</pattern> -->
    			<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %40.40logger{36} %4.4L - %msg%n%ex{full, DISPLAY_EX_EVAL}</pattern>
    			<!-- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %40.40logger{36} %4.4L - %msg%n\n%caller{3, CALLER_DISPLAY_EVAL}\n%ex{full, DISPLAY_EX_EVAL}</pattern> -->
    		</encoder>
    	</appender>
    	<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${catalina.base}/logs/logFile.log</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <fileNamePattern>${catalina.base}/logs/logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
           		<maxHistory>30</maxHistory>
           		<cleanHistoryOnStart>true</cleanHistoryOnStart>
            </rollingPolicy>
            <encoder>
            	<pattern>%d{HH:mm:ss.SSS} [%thread] %-7level %50.50logger{36} %4.4L - %msg%n%ex{full, DISPLAY_EX_EVAL}</pattern>
                <!-- <pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern> -->
            </encoder>
        </appender>
    
    	<!-- Application Loggers -->
    	<logger name="com.dbility.apps" additivity="false">
    		<level value="debug" />
    		<appender-ref ref="console" />
    		<appender-ref ref="file" />
    	</logger>
    
    	<!-- 3rdparty Loggers -->
    	<logger name="org.springframework" additivity="false">
    		<level value="info" />
    		<appender-ref ref="console" />
    		<appender-ref ref="file" />
    	</logger>
    
    	<logger name="jdbc.connection" additivity="false">
    		<level value="info" />
    		<appender-ref ref="console" />
    	</logger>
    
    	<logger name="jdbc.sqlonly" additivity="false">
    		<level value="info" />
    		<appender-ref ref="console" />
    	</logger>
    
    	<logger name="jdbc.resultsettable" additivity="false">
    		<level value="info" />
    		<appender-ref ref="console" />
    	</logger>
    
    	<root level="warn">
    		<appender-ref ref="console" />
    	</root>
    
    </configuration>

 

반응형
Comments