|
@@ -0,0 +1,36 @@
|
|
1
|
+package me.yuxiaoyao.config.log;
|
|
2
|
+
|
|
3
|
+import ch.qos.logback.classic.util.ContextInitializer;
|
|
4
|
+import me.yuxiaoyao.config.loader.ConfigLoader;
|
|
5
|
+import org.slf4j.bridge.SLF4JBridgeHandler;
|
|
6
|
+
|
|
7
|
+import java.io.File;
|
|
8
|
+
|
|
9
|
+/**
|
|
10
|
+ * @author Kerry on 19/10/10
|
|
11
|
+ */
|
|
12
|
+
|
|
13
|
+public class LogSetter {
|
|
14
|
+
|
|
15
|
+ public static void resetLogger() {
|
|
16
|
+ // 第三方JAR包引用了 其他日志LIB,这里统一用 slf4j 统一接管
|
|
17
|
+ // @see https://stackoverflow.com/questions/6020545/send-redirect-route-java-util-logging-logger-jul-to-logback-using-slf4j/20407321
|
|
18
|
+ SLF4JBridgeHandler.removeHandlersForRootLogger();
|
|
19
|
+ SLF4JBridgeHandler.install();
|
|
20
|
+ }
|
|
21
|
+
|
|
22
|
+ public static void setLogback(String basename, String profile) {
|
|
23
|
+ if (profile == null) {
|
|
24
|
+ return;
|
|
25
|
+ }
|
|
26
|
+ File file = new File(ConfigLoader.DEFAULT_FILE_CONFIG_FOLDER + File.separator + basename + "-" + profile + "xml");
|
|
27
|
+ if (file.exists()) {
|
|
28
|
+ System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, file.getAbsolutePath());
|
|
29
|
+ return;
|
|
30
|
+ }
|
|
31
|
+ file = new File(ConfigLoader.DEFAULT_FILE_CONFIG_FOLDER + File.separator + basename + "xml");
|
|
32
|
+ if (file.exists()) {
|
|
33
|
+ System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, file.getAbsolutePath());
|
|
34
|
+ }
|
|
35
|
+ }
|
|
36
|
+}
|