From 6563f512abff3fa0fd78228d3e277b4275697d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=AB=E6=81=92?= Date: Wed, 24 Feb 2021 11:16:07 +0800 Subject: [PATCH 1/2] support logging.file.path --- .gitignore | 1 + .../core/appender/TracerLogRootDaemon.java | 5 ++ .../TracerLogRootDaemonLoggingpathTest.java | 55 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonLoggingpathTest.java diff --git a/.gitignore b/.gitignore index 566aa498b..6574c1ad3 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ bak *.iws .DS_Store nb-configuration.xml +coverage-report logs *.log pom.xml.versionsBackup \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemon.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemon.java index 7376028b3..45d9eff6d 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemon.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemon.java @@ -64,6 +64,11 @@ public class TracerLogRootDaemon { if (StringUtils.isBlank(loggingRoot)) { loggingRoot = System.getProperty("logging.path"); } + // adapter to springboot 2.4.x + if (StringUtils.isBlank(loggingRoot)) { + loggingRoot = System.getProperty("logging.file.path"); + } + if (StringUtils.isBlank(loggingRoot)) { loggingRoot = System.getProperty("user.home") + File.separator + "logs"; } diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonLoggingpathTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonLoggingpathTest.java new file mode 100644 index 000000000..4740934c5 --- /dev/null +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonLoggingpathTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.appender; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; + +import static junit.framework.TestCase.assertEquals; + +/** + * TracerLogRootDaemon Tester. + * + * @author + * @version 1.0 + * @since
July 24, 2017
+ */ +public class TracerLogRootDaemonLoggingpathTest { + + @Before + public void before() throws Exception { + System.setProperty(TracerLogRootDaemon.TRACER_APPEND_PID_TO_LOG_PATH_KEY, "false"); + System.setProperty("logging.file.path", System.getProperty("user.home") + File.separator + + "logs"); + } + + @After + public void after() throws Exception { + System.clearProperty(TracerLogRootDaemon.TRACER_APPEND_PID_TO_LOG_PATH_KEY); + System.clearProperty("logging.file.path"); + } + + @Test + public void testLogRoot() { + assertEquals(TracerLogRootDaemon.LOG_FILE_DIR, System.getProperty("user.home") + + File.separator + "logs/tracelog"); + } + +} From 823aad4715758e8f6922ca23e9501eebfbde129a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=AB=E6=81=92?= Date: Wed, 24 Feb 2021 11:17:51 +0800 Subject: [PATCH 2/2] support logging.file.path --- .../core/appender/TracerLogRootDaemonLoggingpathTest.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonLoggingpathTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonLoggingpathTest.java index 4740934c5..6b624e858 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonLoggingpathTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonLoggingpathTest.java @@ -25,11 +25,9 @@ import static junit.framework.TestCase.assertEquals; /** - * TracerLogRootDaemon Tester. - * - * @author - * @version 1.0 - * @since
July 24, 2017
+ * TracerLogRootDaemonLoggingpathTest + * @author guolei.sgl + * @since v3.1.1 */ public class TracerLogRootDaemonLoggingpathTest {