diff --git a/.gitignore b/.gitignore index 566aa498..6574c1ad 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 9e0f91b1..8817faf1 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 00000000..6b624e85 --- /dev/null +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonLoggingpathTest.java @@ -0,0 +1,53 @@ +/* + * 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; + +/** + * TracerLogRootDaemonLoggingpathTest + * @author guolei.sgl + * @since v3.1.1 + */ +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"); + } + +}