From 11c1e5ed6b7e9ada76215475cb8a1fcf28348bc8 Mon Sep 17 00:00:00 2001 From: David Liu Date: Tue, 28 Oct 2014 14:09:06 +0800 Subject: [PATCH] add for log4j2 --- .../logging/log4j2/Log4J2LoggingSystem.java | 21 ++++++++++- .../boot/logging/log4j2/basic-log4j2.xml | 25 +++++++++++++ .../boot/logging/log4j2/log4j2-console.xml | 27 ++++++++++++++ .../logging/log4j2/log4j2-file-console.xml | 37 +++++++++++++++++++ .../boot/logging/log4j2/log4j2-file.xml | 33 +++++++++++++++++ .../boot/logging/log4j2/log4j2.xml | 21 +++++++++++ 6 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/basic-log4j2.xml create mode 100644 spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-console.xml create mode 100644 spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-file-console.xml create mode 100644 spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-file.xml create mode 100644 spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2.xml diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java b/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java index dc877fa76a..792f0293de 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java @@ -27,6 +27,7 @@ import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.ConfigurationFactory; import org.apache.logging.log4j.core.config.ConfigurationSource; + import org.springframework.boot.logging.LogLevel; import org.springframework.boot.logging.LoggingSystem; import org.springframework.boot.logging.Slf4JLoggingSystem; @@ -56,8 +57,24 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem { LEVELS = Collections.unmodifiableMap(levels); } - public Log4J2LoggingSystem(ClassLoader classLoader) { - super(classLoader, "log4j2.json", "log4j2.jsn", "log4j2.xml"); + public Log4J2LoggingSystem(ClassLoader classLoader, boolean fileOutput, boolean consoleOutput) { + super(classLoader, fileOutput, consoleOutput); + } + + @Override + protected String[] getLogFileName(boolean fileOutput, boolean consoleOutput) { + if (fileOutput && consoleOutput) { + return new String[] { "log4j2-file-console.json", "log4j2-file-console.jsn", "log4j2-file-console.xml" }; + } + else if (fileOutput) { + return new String[] { "log4j2-file.json", "log4j2-file.jsn", "log4j2-file.xml" }; + } + else if (consoleOutput) { + return new String[] { "log4j2-console.json", "log4j2-console.jsn", "log4j2-console.xml" }; + } + else { + return new String[] { "log4j2.json", "log4j2.jsn", "log4j2.xml" }; + } } @Override diff --git a/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/basic-log4j2.xml b/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/basic-log4j2.xml new file mode 100644 index 0000000000..d8e113eac3 --- /dev/null +++ b/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/basic-log4j2.xml @@ -0,0 +1,25 @@ + + + + ???? + [%d{yyyy-MM-dd HH:mm:ss.SSS}] boot%X{context} - ${sys:PID} %5p [%t] --- %c{1}: %m%n + + + + + + + + + + + + + + + + + + + + diff --git a/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-console.xml b/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-console.xml new file mode 100644 index 0000000000..2374d828ef --- /dev/null +++ b/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-console.xml @@ -0,0 +1,27 @@ + + + + ???? + /tmp + ${sys:LOG_PATH}/spring.log + [%d{yyyy-MM-dd HH:mm:ss.SSS}] boot%X{context} - ${sys:PID} %5p [%t] --- %c{1}: %m%n + + + + + + + + + + + + + + + + + + + + diff --git a/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-file-console.xml b/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-file-console.xml new file mode 100644 index 0000000000..e2f1bb78a7 --- /dev/null +++ b/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-file-console.xml @@ -0,0 +1,37 @@ + + + + ???? + /tmp + ${sys:LOG_PATH}/spring.log + [%d{yyyy-MM-dd HH:mm:ss.SSS}] boot%X{context} - ${sys:PID} %5p [%t] --- %c{1}: %m%n + + + + + + + + ${LOG_PATTERN} + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-file.xml b/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-file.xml new file mode 100644 index 0000000000..b1bc0235c0 --- /dev/null +++ b/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-file.xml @@ -0,0 +1,33 @@ + + + + ???? + /tmp + ${sys:LOG_PATH}/spring.log + [%d{yyyy-MM-dd HH:mm:ss.SSS}] boot%X{context} - ${sys:PID} %5p [%t] --- %c{1}: %m%n + + + + + ${LOG_PATTERN} + + + + + + + + + + + + + + + + + + + + diff --git a/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2.xml b/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2.xml new file mode 100644 index 0000000000..eed5a2c784 --- /dev/null +++ b/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2.xml @@ -0,0 +1,21 @@ + + + + ???? + /tmp + ${sys:LOG_PATH}/spring.log + [%d{yyyy-MM-dd HH:mm:ss.SSS}] boot%X{context} - ${sys:PID} %5p [%t] --- %c{1}: %m%n + + + + + + + + + + + + + +