使用log4j记录日志
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.didispace;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
# LOG4J配置
|
||||
log4j.rootCategory=INFO, stdout, file, errorfile
|
||||
log4j.category.com.didispace=DEBUG, didifile
|
||||
log4j.logger.error=errorfile
|
||||
|
||||
# 控制台输出
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
|
||||
|
||||
# root日志输出
|
||||
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.file.file=logs/all.log
|
||||
log4j.appender.file.DatePattern='.'yyyy-MM-dd
|
||||
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
|
||||
|
||||
# error日志输出
|
||||
log4j.appender.errorfile=org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.errorfile.file=logs/error.log
|
||||
log4j.appender.errorfile.DatePattern='.'yyyy-MM-dd
|
||||
log4j.appender.errorfile.Threshold = ERROR
|
||||
log4j.appender.errorfile.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.errorfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
|
||||
|
||||
# com.didispace下的日志输出
|
||||
log4j.appender.didifile=org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.didifile.file=logs/my.log
|
||||
log4j.appender.didifile.DatePattern='.'yyyy-MM-dd
|
||||
log4j.appender.didifile.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.didifile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L ---- %m%n
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.didispace;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = Application.class)
|
||||
public class ApplicationTests {
|
||||
|
||||
private Logger logger = Logger.getLogger(getClass());
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
logger.info("输出info");
|
||||
logger.debug("输出debug");
|
||||
logger.error("输出error");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user