logback.xmlをプロジェクトのローカルに置くだけで自動的に認識する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
private static Logger logger = LoggerFactory.getLogger(Test.class); private static void writeLog(){ logger.info(formatLog(new String[] {"kotei", className,messege})); } /** * ログのフォーマット * @param data文字列の配列 * @return フォーマット文字列 */ private static String formatLog(String[] data) { MessageFormat format; if (data.length == 3) { format= new MessageFormat("[{1}][{0}]{2}"); } else { format= new MessageFormat("[{1}][{0}]"); } return format.format(data); } |
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 32 33 34 35 |
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration> <configuration debug="false"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern>%d{yyyy/MM/dd HH:mm:ss.SSS} %-5level:%msg%n</pattern> </layout> </appender> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>INFO</level> </filter> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern>%d{yyyy/MM/dd HH:mm:ss.SSS} %-5level:%msg%n</pattern> </layout> <File>../../logs/test.log</File> <!-- daily log --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>../../logs/test.%d{yyyy-MM-dd}.log</FileNamePattern> <MaxHistory>10</MaxHistory> </rollingPolicy> </appender> <root level="debug"> <appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> </root> </configuration> |