사용

Print internal state

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.util.StatusPrinter;


public class Test {
 
@Test
	public void test() {
		// print internal state
	    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
	    StatusPrinter.print(lc);
	    
		fail("Not yet implemented");
	}


LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
StatusPrinter.print(lc);

 

설정 파일

위치

  • src
    • main
      • resources
        • logback.xml
    • test
      • resources
        • logback-test.xml

 

logback.xml

http://logback.qos.ch/manual/configuration.html

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds">
	<appender name="FILE"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>logs/my-web-app.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<!-- daily rollover -->
			<fileNamePattern>logs/nca-web-app.log.%d{yyyy-MM-dd}.log
			</fileNamePattern>
			<!-- keep 30 days' worth of history -->
			<maxHistory>30</maxHistory> 
		</rollingPolicy>
		<encoder>
			<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n
			</pattern>
		</encoder>
	</appender>
	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
		<encoder>
			<pattern>
				%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
			</pattern>
		</encoder>
	</appender>
	<logger name="com.example.mypackage" level="DEBUG" />
	<logger name="org.springframework" level="INFO" />
	<!-- turn OFF all logging (children can override) -->
	<root level="INFO">
		<appender-ref ref="STDOUT" />
		<appender-ref ref="FILE" />
	</root>
</configuration>

 

Ref