提交 a71c3abe 编写于 作者: A Alan Lau 提交者: wu-sheng

Add cached writer. (#3287)

* Add cached writer so we need not call whole method.

* Make writer volatile.

* Make writer to WRITER.

* Rewrite the writeFactory for add the cached writer and keep the unit tests stable.

* Give the default writer.

* Remove volatile.
上级 c2663c08
......@@ -25,23 +25,37 @@ import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.conf.SnifferConfigInitializer;
import org.apache.skywalking.apm.util.StringUtil;
/**
* @author Alan Lau
*/
public class WriterFactory {
private static IWriter WRITER;
public static IWriter getLogWriter() {
if (!useConsole() && SnifferConfigInitializer.isInitCompleted() && AgentPackagePath.isPathFound()) {
if (StringUtil.isEmpty(Config.Logging.DIR)) {
try {
Config.Logging.DIR = AgentPackagePath.getPath() + "/logs";
} catch (AgentPackageNotFoundException e) {
e.printStackTrace();
switch (Config.Logging.OUTPUT) {
case FILE:
if (WRITER != null) {
return WRITER;
}
}
return FileWriter.get();
} else {
return SystemOutWriter.INSTANCE;
}
}
if (SnifferConfigInitializer.isInitCompleted() && AgentPackagePath.isPathFound()) {
if (StringUtil.isEmpty(Config.Logging.DIR)) {
try {
Config.Logging.DIR = AgentPackagePath.getPath() + "/logs";
} catch (AgentPackageNotFoundException e) {
e.printStackTrace();
}
}
WRITER = FileWriter.get();
} else {
return SystemOutWriter.INSTANCE;
}
break;
default:
return SystemOutWriter.INSTANCE;
private static boolean useConsole() {
return LogOutput.CONSOLE == Config.Logging.OUTPUT;
}
return WRITER;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册