Java

java applicaiton logback 설정

순수 java application 개발 시 logback 사용 설정


5라인에서 config 하도록 설정


1
2
3
4
5
6
7
8
9
10
11
12
13
public class FileRead {
    private static final Logger logger = LoggerFactory.getLogger(FileRead.class);
 
    static {
        BasicConfigurator.configure();
    }
 
    public static void main(String[] args){
        logger.info("test");
 
        logger.info("test end");
    }
}
cs




resources 아래에 logback.xml 로  logback 설정파일을 만들어야 함

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Appenders>
        <Console name="console" target="SYSTEM_OUT" class="org.apache.log4j.ConsoleAppender">
            <PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss}] %-5p: %c - %m%n" />
        </Console>
    </Appenders>
    <Loggers>
        <Logger name="java.sql.Connection" level="DEBUG"  additivity="false">
             <AppenderRef ref="console" />
        </Logger>
 
        <Logger name="java.sql.Statement" level="DEBUG"  additivity="false">
            <AppenderRef ref="console" />
        </Logger>
 
        <Logger name="java.sql.PreparedStatement" level="DEBUG"  additivity="false">
            <AppenderRef ref="console" />
        </Logger>
 
        <Logger name="java.sql.ResultSet" level="TRACE"  additivity="false">
            <AppenderRef ref="console" />
        </Logger>
        <Logger name="java.sql.CallableStatement" level="DEBUG"  additivity="false">
            <AppenderRef ref="console" />
        </Logger>
        <Root level="DEBUG">
            <AppenderRef ref="console" />
        </Root>
    </Loggers>
</Configuration>
cs



참고링크 : https://github.com/sonegy/how-to-use-logback

  https://stackoverflow.com/questions/12532339/no-appenders-could-be-found-for-loggerlog4j