Skip to content

Commit

Permalink
Feature/support custom tracer logging path (#331)
Browse files Browse the repository at this point in the history
* support custom tracer logging path
  • Loading branch information
xzchaoo authored Feb 10, 2020
1 parent 69f499b commit 93d487a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ nb-configuration.xml
coverage-report
logs
*.log
pom.xml.versionsBackup
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void destroy() {
//wait for async output
List<String> result = FileUtils.readLines(new File(logDirectoryPath + File.separator
+ "tracer-self.log"));
Assert.assertTrue(result.size() == 1);
Assert.assertTrue(result.size() == 2);
}

private void checkFile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
*/
package com.alipay.common.tracer.core.appender;

import java.io.File;
import java.nio.charset.Charset;

import com.alipay.common.tracer.core.appender.self.SelfLog;
import com.alipay.common.tracer.core.appender.self.TracerDaemon;
import com.alipay.common.tracer.core.utils.StringUtils;
import com.alipay.common.tracer.core.utils.TracerUtils;

import java.io.File;
import java.nio.charset.Charset;

/**
* TracerLogRootDaemon
*
* <p>
* Not obtained from the configuration project, obtained directly from the system properties
*
* @author yangguanchao
Expand Down Expand Up @@ -55,17 +55,22 @@ public class TracerLogRootDaemon {

static {
String loggingRoot = System.getProperty("loggingRoot");
if (StringUtils.isBlank(loggingRoot)) {
loggingRoot = System.getProperty("SOFA_TRACER_LOGGING_PATH");
}
if (StringUtils.isBlank(loggingRoot)) {
loggingRoot = System.getenv("SOFA_TRACER_LOGGING_PATH");
}
if (StringUtils.isBlank(loggingRoot)) {
loggingRoot = System.getProperty("logging.path");
}

String appendPidToLogPathString = System.getProperty(TRACER_APPEND_PID_TO_LOG_PATH_KEY);
boolean appendPidToLogPath = "true".equalsIgnoreCase(appendPidToLogPathString);

if (StringUtils.isBlank(loggingRoot)) {
loggingRoot = System.getProperty("user.home") + File.separator + "logs";
}

String appendPidToLogPathString = System.getProperty(TRACER_APPEND_PID_TO_LOG_PATH_KEY);
boolean appendPidToLogPath = "true".equalsIgnoreCase(appendPidToLogPathString);

String tempLogFileDir = loggingRoot + File.separator + "tracelog";

if (appendPidToLogPath) {
Expand All @@ -76,6 +81,7 @@ public class TracerLogRootDaemon {

try {
TracerDaemon.start();
SelfLog.info("LOG_FILE_DIR is " + LOG_FILE_DIR);
} catch (Throwable e) {
SelfLog.error("Failed to start Tracer Daemon Thread", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void test() throws IOException, InterruptedException {
timedRollingFileAppender.append(content);

// wait to rolling
Thread.sleep(1100);
Thread.sleep(1500);

timedRollingFileAppender.append(content);
timedRollingFileAppender.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/
@Configuration
@EnableConfigurationProperties(ZipkinSofaTracerProperties.class)
@ConditionalOnProperty(value = "com.alipay.sofa.tracer.zipkin.enabled", matchIfMissing = true)
@ConditionalOnProperty(value = "com.alipay.sofa.tracer.zipkin.enabled", matchIfMissing = false)
@ConditionalOnClass({ zipkin2.Span.class, zipkin2.reporter.AsyncReporter.class, RestTemplate.class })
public class ZipkinSofaTracerAutoConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public class ZipkinSofaTracerProperties {
* URL of the zipkin query server instance.
*/
private String baseUrl = "http://localhost:9411/";
private boolean enabled = true;
/**
* zipkin reporter is disabled by default
*/
private boolean enabled = false;
/**
* When enabled, spans are gzipped before sent to the zipkin server
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@
*/
package com.alipay.sofa.tracer.boot.springmvc;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterCycleTimesManager;
import com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager;
import com.alipay.sofa.tracer.boot.TestUtil;
import com.alipay.sofa.tracer.boot.base.AbstractTestBase;
import com.alipay.sofa.tracer.boot.base.SpringBootWebApplication;
import com.alipay.sofa.tracer.boot.base.controller.SampleRestController;
import com.alipay.sofa.tracer.plugins.springmvc.SpringMvcLogEnum;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -35,8 +29,15 @@
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.Assert;

import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterCycleTimesManager;
import com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager;
import com.alipay.sofa.tracer.boot.TestUtil;
import com.alipay.sofa.tracer.boot.base.AbstractTestBase;
import com.alipay.sofa.tracer.boot.base.SpringBootWebApplication;
import com.alipay.sofa.tracer.boot.base.controller.SampleRestController;
import com.alipay.sofa.tracer.plugins.springmvc.SpringMvcLogEnum;

import static org.junit.Assert.*;

Expand Down Expand Up @@ -101,7 +102,9 @@ public void testSofaRestGet() throws Exception {
//wait for async output
List<String> statContents = FileUtils
.readLines(customFileLog(SpringMvcLogEnum.SPRING_MVC_STAT.getDefaultLogName()));
assertEquals(2, statContents.size());

// 在很慢的机器上此处不能保证一定是2条, 但>=2
assertTrue(statContents.size() >= 2);
}

private static <K, V> Map<K, V> parseToMap(String json, Class<K> keyType, Class<V> valueType) {
Expand Down

0 comments on commit 93d487a

Please sign in to comment.