提交 04771ffc 编写于 作者: wu-sheng's avatar wu-sheng

Adjust log APIs.

上级 030f7c63
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017, OpenSkywalking Organization All rights reserved.
~
~ Licensed 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.
~
~ Project repository: https://github.com/OpenSkywalking/skywalking
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apm-commons</artifactId>
<groupId>org.skywalking</groupId>
<version>3.2.3-2017</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apm-logging-api</artifactId>
</project>
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.logging;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.powermock.api.support.membermodification.MemberModifier;
/**
* @author wusheng
*/
public class LogManagerTest {
@Test
public void testGetNoopLogger() {
ILog logger = LogManager.getLogger(LogManagerTest.class);
Assert.assertEquals(NoopLogger.INSTANCE, logger);
}
@Before
@After
public void clear() throws IllegalAccessException {
MemberModifier.field(LogManager.class, "RESOLVER").set(null, null);
}
public class TestLogger implements ILog {
@Override
public void info(String format) {
}
@Override
public void info(String format, Object... arguments) {
}
@Override
public void warn(String format, Object... arguments) {
}
@Override
public void error(String format, Throwable e) {
}
@Override
public void error(Throwable e, String format, Object... arguments) {
}
@Override
public boolean isDebugEnable() {
return false;
}
@Override
public boolean isInfoEnable() {
return false;
}
@Override
public boolean isWarnEnable() {
return false;
}
@Override
public boolean isErrorEnable() {
return false;
}
@Override
public void debug(String format) {
}
@Override
public void debug(String format, Object... arguments) {
}
@Override
public void error(String format) {
}
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.logging;
import org.junit.Assert;
import org.junit.Test;
/**
* Created by wusheng on 2017/2/27.
*/
public class NoopLoggerTest {
@Test
public void testOnNothing() {
Assert.assertFalse(NoopLogger.INSTANCE.isDebugEnable());
Assert.assertFalse(NoopLogger.INSTANCE.isInfoEnable());
Assert.assertFalse(NoopLogger.INSTANCE.isErrorEnable());
Assert.assertFalse(NoopLogger.INSTANCE.isWarnEnable());
NoopLogger.INSTANCE.debug("Any string");
NoopLogger.INSTANCE.debug("Any string", new Object[0]);
NoopLogger.INSTANCE.info("Any string");
NoopLogger.INSTANCE.info("Any string", new Object[0]);
NoopLogger.INSTANCE.warn("Any string", new Object[0]);
NoopLogger.INSTANCE.warn("Any string", new Object[0], new NullPointerException());
NoopLogger.INSTANCE.error("Any string");
NoopLogger.INSTANCE.error("Any string", new NullPointerException());
}
}
......@@ -30,7 +30,6 @@
<modules>
<module>apm-util</module>
<module>apm-logging-api</module>
<module>apm-datacarrier</module>
</modules>
......
......@@ -53,11 +53,6 @@
</properties>
<dependencies>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-logging-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-network</artifactId>
......
......@@ -18,15 +18,19 @@
package org.skywalking.apm.agent.core.boot;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.skywalking.apm.agent.core.logging.SystemOutWriter;
/**
* @author wusheng
*/
public class AgentPackagePath {
private static final ILog logger = LogManager.getLogger(AgentPackagePath.class);
private static File AGENT_PACKAGE_PATH;
public static File getPath() throws AgentPackageNotFoundException {
......@@ -36,6 +40,10 @@ public class AgentPackagePath {
return AGENT_PACKAGE_PATH;
}
public static boolean isPathFound() {
return AGENT_PACKAGE_PATH != null;
}
private static File findPath() throws AgentPackageNotFoundException {
String classResourcePath = AgentPackagePath.class.getName().replaceAll("\\.", "/") + ".class";
......@@ -43,7 +51,7 @@ public class AgentPackagePath {
if (resource != null) {
String urlString = resource.toString();
SystemOutWriter.INSTANCE.write(urlString);
logger.debug("The beacon class location is {}.", urlString);
int insidePathIndex = urlString.indexOf('!');
boolean isInJar = insidePathIndex > -1;
......@@ -54,7 +62,7 @@ public class AgentPackagePath {
try {
agentJarFile = new File(new URL(urlString).getFile());
} catch (MalformedURLException e) {
SystemOutWriter.INSTANCE.write("Can not locate agent jar file by url:" + urlString);
logger.error(e, "Can not locate agent jar file by url:" + urlString);
}
if (agentJarFile.exists()) {
return agentJarFile.getParentFile();
......@@ -65,7 +73,7 @@ public class AgentPackagePath {
}
}
SystemOutWriter.INSTANCE.write("Can not locate agent jar file.");
logger.error("Can not locate agent jar file.");
throw new AgentPackageNotFoundException("Can not locate agent jar file.");
}
......
......@@ -22,8 +22,8 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.ServiceLoader;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
/**
* The <code>ServiceManager</code> bases on {@link ServiceLoader},
......
......@@ -21,8 +21,8 @@ package org.skywalking.apm.agent.core.conf;
import java.util.LinkedList;
import java.util.List;
import org.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.skywalking.apm.agent.core.logging.LogLevel;
import org.skywalking.apm.agent.core.logging.WriterFactory;
import org.skywalking.apm.agent.core.logging.core.LogLevel;
import org.skywalking.apm.agent.core.logging.core.WriterFactory;
/**
* This is the core config in sniffer agent.
......
......@@ -18,6 +18,13 @@
package org.skywalking.apm.agent.core.conf;
import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
import org.skywalking.apm.agent.core.boot.AgentPackagePath;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import org.skywalking.apm.util.ConfigInitializer;
import org.skywalking.apm.util.StringUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
......@@ -25,11 +32,6 @@ import java.io.InputStream;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
import org.skywalking.apm.agent.core.boot.AgentPackagePath;
import org.skywalking.apm.agent.core.logging.SystemOutWriter;
import org.skywalking.apm.util.ConfigInitializer;
import org.skywalking.apm.util.StringUtil;
/**
* The <code>SnifferConfigInitializer</code> initializes all configs in several way.
......@@ -38,16 +40,17 @@ import org.skywalking.apm.util.StringUtil;
* @see {@link #initialize()}, to learn more about how to initialzie.
*/
public class SnifferConfigInitializer {
private static final ILog logger = LogManager.getLogger(SnifferConfigInitializer.class);
private static String CONFIG_FILE_NAME = "/config/agent.config";
private static String ENV_KEY_PREFIX = "skywalking.";
/**
* Try to locate `agent.config`, which should be in the /config dictionary of agent package.
*
* <p>
* Also try to override the config by system.env and system.properties. All the keys in these two places should
* start with {@link #ENV_KEY_PREFIX}. e.g. in env `skywalking.agent.application_code=yourAppName` to override
* `agent.application_code` in config file.
*
* <p>
* At the end, `agent.application_code` and `collector.servers` must be not blank.
*/
public static void initialize() throws ConfigNotFoundException, AgentPackageNotFoundException {
......@@ -59,15 +62,13 @@ public class SnifferConfigInitializer {
properties.load(configFileStream);
ConfigInitializer.initialize(properties, Config.class);
} catch (Exception e) {
SystemOutWriter.INSTANCE.write("Failed to read the config file, skywalking is going to run in default config.");
e.printStackTrace(SystemOutWriter.INSTANCE.getStream());
logger.error(e, "Failed to read the config file, skywalking is going to run in default config.");
}
try {
overrideConfigBySystemEnv();
} catch (Exception e) {
SystemOutWriter.INSTANCE.write("Failed to read the system env.");
e.printStackTrace(SystemOutWriter.INSTANCE.getStream());
logger.error(e, "Failed to read the system env.");
}
if (StringUtil.isEmpty(Config.Agent.APPLICATION_CODE)) {
......@@ -81,7 +82,7 @@ public class SnifferConfigInitializer {
/**
* Override the config by system env. The env key must start with `skywalking`, the reuslt should be as same as in
* `agent.config`
*
* <p>
* such as:
* Env key of `agent.application_code` shoule be `skywalking.agent.application_code`
*
......@@ -89,13 +90,6 @@ public class SnifferConfigInitializer {
*/
private static void overrideConfigBySystemEnv() throws IllegalAccessException {
Properties properties = new Properties();
Map<String, String> envs = System.getenv();
for (String envKey : envs.keySet()) {
if (envKey.startsWith(ENV_KEY_PREFIX)) {
String realKey = envKey.substring(ENV_KEY_PREFIX.length());
properties.setProperty(realKey, envs.get(envKey));
}
}
Properties systemProperties = System.getProperties();
Iterator<Map.Entry<Object, Object>> entryIterator = systemProperties.entrySet().iterator();
while (entryIterator.hasNext()) {
......@@ -105,6 +99,15 @@ public class SnifferConfigInitializer {
properties.put(realKey, prop.getValue());
}
}
Map<String, String> envs = System.getenv();
for (String envKey : envs.keySet()) {
if (envKey.startsWith(ENV_KEY_PREFIX)) {
String realKey = envKey.substring(ENV_KEY_PREFIX.length());
properties.setProperty(realKey, envs.get(envKey));
}
}
if (!properties.isEmpty()) {
ConfigInitializer.initialize(properties, Config.class);
}
......@@ -119,13 +122,13 @@ public class SnifferConfigInitializer {
File configFile = new File(AgentPackagePath.getPath(), CONFIG_FILE_NAME);
if (configFile.exists() && configFile.isFile()) {
try {
SystemOutWriter.INSTANCE.write(CONFIG_FILE_NAME + " file found in agent folder.");
logger.info("Config file found in {}.", configFile);
return new FileInputStream(configFile);
} catch (FileNotFoundException e) {
throw new ConfigNotFoundException("Fail to load agent.config", e);
}
}
throw new ConfigNotFoundException("Fail to load agent.config");
throw new ConfigNotFoundException("Fail to load agent config file.");
}
}
......@@ -26,8 +26,8 @@ import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.skywalking.apm.agent.core.sampling.SamplingService;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import org.skywalking.apm.util.StringUtil;
/**
......
......@@ -26,8 +26,8 @@ import org.skywalking.apm.agent.core.context.ids.DistributedTraceIds;
import org.skywalking.apm.agent.core.context.ids.GlobalIdGenerator;
import org.skywalking.apm.agent.core.context.ids.ID;
import org.skywalking.apm.agent.core.context.ids.NewDistributedTraceId;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import org.skywalking.apm.network.proto.TraceSegmentObject;
import org.skywalking.apm.network.proto.UpstreamSegment;
......
......@@ -37,8 +37,8 @@ import org.skywalking.apm.agent.core.jvm.memorypool.MemoryPoolProvider;
import org.skywalking.apm.agent.core.remote.GRPCChannelListener;
import org.skywalking.apm.agent.core.remote.GRPCChannelManager;
import org.skywalking.apm.agent.core.remote.GRPCChannelStatus;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import org.skywalking.apm.network.proto.JVMMetric;
import org.skywalking.apm.network.proto.JVMMetrics;
import org.skywalking.apm.network.proto.JVMMetricsServiceGrpc;
......
......@@ -19,8 +19,8 @@
package org.skywalking.apm.agent.core.jvm.cpu;
import org.skywalking.apm.agent.core.os.ProcessorUtil;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import org.skywalking.apm.network.proto.CPU;
/**
......
......@@ -16,7 +16,7 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.logging;
package org.skywalking.apm.agent.core.logging.api;
/**
* The Log interface.
......
......@@ -16,7 +16,9 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.logging;
package org.skywalking.apm.agent.core.logging.api;
import org.skywalking.apm.agent.core.logging.core.EasyLogResolver;
/**
* LogManager is the {@link LogResolver} implementation manager. By using {@link LogResolver}, {@link
......@@ -27,7 +29,7 @@ package org.skywalking.apm.logging;
* override the first without any warning or exception. <p> Created by xin on 2016/11/10.
*/
public class LogManager {
private static LogResolver RESOLVER;
private static LogResolver RESOLVER = new EasyLogResolver();
public static void setLogResolver(LogResolver resolver) {
LogManager.RESOLVER = resolver;
......
......@@ -16,7 +16,7 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.logging;
package org.skywalking.apm.agent.core.logging.api;
/**
* {@link LogResolver} just do only one thing: return the {@link ILog} implementation.
......
......@@ -16,7 +16,7 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.logging;
package org.skywalking.apm.agent.core.logging.api;
/**
* No operation logger implementation.
......
......@@ -16,10 +16,10 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.agent.core.logging;
package org.skywalking.apm.agent.core.logging.core;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogResolver;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogResolver;
/**
* Created by wusheng on 2016/11/26.
......
......@@ -16,7 +16,7 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.agent.core.logging;
package org.skywalking.apm.agent.core.logging.core;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
......@@ -25,7 +25,7 @@ import java.util.Date;
import java.util.regex.Matcher;
import org.skywalking.apm.agent.core.conf.Config;
import org.skywalking.apm.agent.core.conf.Constants;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.util.StringUtil;
/**
......@@ -41,7 +41,7 @@ public class EasyLogger implements ILog {
this.targetClass = targetClass;
}
private void logger(LogLevel level, String message, Throwable e) {
protected void logger(LogLevel level, String message, Throwable e) {
WriterFactory.getLogWriter().write(format(level, message, e));
}
......
......@@ -16,7 +16,7 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.agent.core.logging;
package org.skywalking.apm.agent.core.logging.core;
import com.lmax.disruptor.EventFactory;
import com.lmax.disruptor.EventHandler;
......
......@@ -16,7 +16,7 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.agent.core.logging;
package org.skywalking.apm.agent.core.logging.core;
public interface IWriter {
void write(String message);
......
......@@ -16,7 +16,7 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.agent.core.logging;
package org.skywalking.apm.agent.core.logging.core;
/**
* Created by xin on 2016/12/7.
......
......@@ -16,7 +16,7 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.agent.core.logging;
package org.skywalking.apm.agent.core.logging.core;
/**
* The <code>LogMessageHolder</code> is a {@link String} holder,
......
......@@ -16,7 +16,7 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.agent.core.logging;
package org.skywalking.apm.agent.core.logging.core;
import java.io.PrintStream;
......@@ -34,8 +34,4 @@ public enum SystemOutWriter implements IWriter {
PrintStream out = System.out;
out.println(message);
}
public PrintStream getStream() {
return System.out;
}
}
......@@ -16,14 +16,23 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.agent.core.logging;
package org.skywalking.apm.agent.core.logging.core;
import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
import org.skywalking.apm.agent.core.boot.AgentPackagePath;
import org.skywalking.apm.agent.core.conf.Config;
import org.skywalking.apm.util.StringUtil;
public class WriterFactory {
public static IWriter getLogWriter() {
if (!StringUtil.isEmpty(Config.Logging.DIR)) {
if (AgentPackagePath.isPathFound()) {
if (StringUtil.isEmpty(Config.Logging.DIR)) {
try {
Config.Logging.DIR = AgentPackagePath.getPath() + "/logs";
} catch (AgentPackageNotFoundException e) {
e.printStackTrace();
}
}
return FileWriter.get();
} else {
return SystemOutWriter.INSTANCE;
......
......@@ -21,8 +21,8 @@ package org.skywalking.apm.agent.core.plugin;
import net.bytebuddy.dynamic.DynamicType;
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine;
import org.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import org.skywalking.apm.util.StringUtil;
/**
......
......@@ -23,8 +23,8 @@ import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
import org.skywalking.apm.agent.core.plugin.loader.AgentClassLoader;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
/**
* Plugins finder.
......
......@@ -25,8 +25,8 @@ import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.agent.core.plugin.exception.IllegalPluginDefineException;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
public enum PluginCfg {
INSTANCE;
......
......@@ -24,8 +24,8 @@ import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import org.skywalking.apm.agent.core.plugin.loader.AgentClassLoader;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
/**
* Use the current classloader to read all plugin define file.
......
......@@ -30,8 +30,8 @@ import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoin
import org.skywalking.apm.agent.core.plugin.interceptor.EnhanceException;
import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import org.skywalking.apm.util.StringUtil;
import static net.bytebuddy.jar.asm.Opcodes.ACC_PRIVATE;
......
......@@ -23,8 +23,8 @@ import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.This;
import org.skywalking.apm.agent.core.plugin.PluginException;
import org.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
/**
* The actual byte-buddy's interceptor to intercept constructor methods.
......
......@@ -27,8 +27,8 @@ import net.bytebuddy.implementation.bind.annotation.SuperCall;
import net.bytebuddy.implementation.bind.annotation.This;
import org.skywalking.apm.agent.core.plugin.PluginException;
import org.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
/**
* The actual byte-buddy's interceptor to intercept class instance methods.
......
......@@ -26,8 +26,8 @@ import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.This;
import org.skywalking.apm.agent.core.plugin.PluginException;
import org.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
/**
* The actual byte-buddy's interceptor to intercept class instance methods.
......
......@@ -25,8 +25,8 @@ import net.bytebuddy.implementation.bind.annotation.Origin;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.SuperCall;
import org.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
/**
* The actual byte-buddy's interceptor to intercept class instance methods.
......
......@@ -24,8 +24,8 @@ import net.bytebuddy.implementation.bind.annotation.Morph;
import net.bytebuddy.implementation.bind.annotation.Origin;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import org.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
/**
* The actual byte-buddy's interceptor to intercept class instance methods.
......
......@@ -21,8 +21,8 @@ package org.skywalking.apm.agent.core.plugin.loader;
import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
import org.skywalking.apm.agent.core.boot.AgentPackagePath;
import org.skywalking.apm.agent.core.plugin.PluginBootstrap;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import java.io.*;
import java.net.MalformedURLException;
......
......@@ -19,8 +19,8 @@
package org.skywalking.apm.agent.core.plugin.loader;
import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
......
......@@ -35,8 +35,8 @@ import org.skywalking.apm.agent.core.dictionary.ApplicationDictionary;
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.skywalking.apm.agent.core.dictionary.OperationNameDictionary;
import org.skywalking.apm.agent.core.os.OSUtil;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import org.skywalking.apm.network.proto.Application;
import org.skywalking.apm.network.proto.ApplicationInstance;
import org.skywalking.apm.network.proto.ApplicationInstanceHeartbeat;
......
......@@ -31,8 +31,8 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.skywalking.apm.agent.core.conf.Config;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import static org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig.Collector.GRPC_SERVERS;
......
......@@ -35,8 +35,8 @@ import org.skywalking.apm.agent.core.boot.BootService;
import org.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory;
import org.skywalking.apm.agent.core.conf.Config;
import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
/**
* @author wusheng
......
......@@ -29,8 +29,8 @@ import org.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.skywalking.apm.commons.datacarrier.DataCarrier;
import org.skywalking.apm.commons.datacarrier.buffer.BufferStrategy;
import org.skywalking.apm.commons.datacarrier.consumer.IConsumer;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import org.skywalking.apm.network.proto.Downstream;
import org.skywalking.apm.network.proto.TraceSegmentServiceGrpc;
import org.skywalking.apm.network.proto.UpstreamSegment;
......
......@@ -27,8 +27,8 @@ import org.skywalking.apm.agent.core.boot.BootService;
import org.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory;
import org.skywalking.apm.agent.core.conf.Config;
import org.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
/**
* The <code>SamplingService</code> take charge of how to sample the {@link TraceSegment}. Every {@link TraceSegment}s
......
......@@ -21,7 +21,7 @@ package org.skywalking.apm.agent.core.conf;
import org.junit.AfterClass;
import org.junit.Test;
import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
import org.skywalking.apm.agent.core.logging.LogLevel;
import org.skywalking.apm.agent.core.logging.core.LogLevel;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
......
......@@ -16,7 +16,7 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.agent.core.logging;
package org.skywalking.apm.agent.core.logging.core;
import org.junit.Assert;
import org.junit.Test;
......
......@@ -16,9 +16,8 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.agent.core.logging;
package org.skywalking.apm.agent.core.logging.core;
import java.io.PrintStream;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
......@@ -26,6 +25,8 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.skywalking.apm.agent.core.conf.Constants;
import java.io.PrintStream;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.times;
......@@ -48,7 +49,12 @@ public class EasyLoggerTest {
System.setOut(output);
PrintStream err = Mockito.mock(PrintStream.class);
System.setErr(err);
EasyLogger logger = new EasyLogger(EasyLoggerTest.class);
EasyLogger logger = new EasyLogger(EasyLoggerTest.class) {
@Override
protected void logger(LogLevel level, String message, Throwable e) {
SystemOutWriter.INSTANCE.write(format(level, message, e));
}
};
Assert.assertTrue(logger.isDebugEnable());
Assert.assertTrue(logger.isInfoEnable());
......@@ -67,7 +73,7 @@ public class EasyLoggerTest {
logger.error(new NullPointerException(), "hello {}", "world");
Mockito.verify(output, times(9))
.println(anyString());
.println(anyString());
}
@Test
......@@ -76,7 +82,12 @@ public class EasyLoggerTest {
System.setOut(output);
PrintStream err = Mockito.mock(PrintStream.class);
System.setErr(err);
EasyLogger logger = new EasyLogger(EasyLoggerTest.class);
EasyLogger logger = new EasyLogger(EasyLoggerTest.class) {
@Override
protected void logger(LogLevel level, String message, Throwable e) {
SystemOutWriter.INSTANCE.write(format(level, message, e));
}
};
Assert.assertTrue(logger.isDebugEnable());
Assert.assertTrue(logger.isInfoEnable());
......@@ -95,7 +106,7 @@ public class EasyLoggerTest {
logger.error(new NullPointerException(), "hello {}", "&&&**%%");
Mockito.verify(output, times(9))
.println(anyString());
.println(anyString());
}
@Test
......@@ -105,7 +116,7 @@ public class EasyLoggerTest {
String formatLines = logger.format(exception);
String[] lines = formatLines.split(Constants.LINE_SEPARATOR);
Assert.assertEquals("java.lang.NullPointerException", lines[1]);
Assert.assertEquals("\tat org.skywalking.apm.agent.core.logging.EasyLoggerTest.testFormat(EasyLoggerTest.java:103)", lines[2]);
Assert.assertEquals("\tat org.skywalking.apm.agent.core.logging.core.EasyLoggerTest.testFormat(EasyLoggerTest.java:114)", lines[2]);
}
@AfterClass
......
......@@ -16,16 +16,17 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.agent.core.logging;
package org.skywalking.apm.agent.core.logging.core;
import java.io.File;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.skywalking.apm.agent.core.conf.Config;
import org.skywalking.apm.agent.core.conf.Constants;
import java.io.File;
import java.io.IOException;
/**
* @author wusheng
*/
......
......@@ -16,14 +16,15 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.agent.core.logging;
package org.skywalking.apm.agent.core.logging.core;
import java.io.PrintStream;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import java.io.PrintStream;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.times;
......
......@@ -16,16 +16,16 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.agent.core.logging;
package org.skywalking.apm.agent.core.logging.core;
import java.io.PrintStream;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import org.skywalking.apm.agent.core.conf.Config;
import java.io.PrintStream;
/**
* Created by wusheng on 2017/2/28.
*/
......@@ -43,10 +43,6 @@ public class WriterFactoryTest {
*/
@Test
public void testGetLogWriter() {
PrintStream mockStream = Mockito.mock(PrintStream.class);
System.setErr(mockStream);
Assert.assertEquals(SystemOutWriter.INSTANCE, WriterFactory.getLogWriter());
Config.Logging.DIR = "/only/test/folder";
Assert.assertTrue(WriterFactory.getLogWriter() instanceof FileWriter);
}
......
......@@ -112,6 +112,7 @@
<copy file="${project.build.directory}/skywalking-agent.jar"
tofile="${project.basedir}/../../packages/skywalking-agent/skywalking-agent.jar" overwrite="true"/>
<mkdir dir="${project.basedir}/../../packages/skywalking-agent/config"/>
<mkdir dir="${project.basedir}/../../packages/skywalking-agent/logs"/>
<copydir src="${project.basedir}/../config"
dest="${project.basedir}/../../packages/skywalking-agent/config" forceoverwrite="true"/>
</tasks>
......
......@@ -18,23 +18,18 @@
package org.skywalking.apm.agent;
import java.lang.instrument.Instrumentation;
import java.util.List;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.utility.JavaModule;
import org.skywalking.apm.agent.core.boot.ServiceManager;
import org.skywalking.apm.agent.core.conf.SnifferConfigInitializer;
import org.skywalking.apm.agent.core.logging.EasyLogResolver;
import org.skywalking.apm.agent.core.logging.SystemOutWriter;
import org.skywalking.apm.agent.core.plugin.AbstractClassEnhancePluginDefine;
import org.skywalking.apm.agent.core.plugin.EnhanceContext;
import org.skywalking.apm.agent.core.plugin.PluginBootstrap;
import org.skywalking.apm.agent.core.plugin.PluginException;
import org.skywalking.apm.agent.core.plugin.PluginFinder;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import org.skywalking.apm.agent.core.plugin.*;
import java.lang.instrument.Instrumentation;
import java.util.List;
/**
* The main entrance of sky-waking agent,
......@@ -43,12 +38,7 @@ import org.skywalking.apm.logging.LogManager;
* @author wusheng
*/
public class SkyWalkingAgent {
private static final ILog logger;
static {
LogManager.setLogResolver(new EasyLogResolver());
logger = LogManager.getLogger(SkyWalkingAgent.class);
}
private static final ILog logger = LogManager.getLogger(SkyWalkingAgent.class);
/**
* Main entrance.
......@@ -67,8 +57,7 @@ public class SkyWalkingAgent {
ServiceManager.INSTANCE.boot();
} catch (Exception e) {
SystemOutWriter.INSTANCE.write("skywalking agent is shutting down.");
e.printStackTrace(SystemOutWriter.INSTANCE.getStream());
logger.error(e, "Skywalking agent initialized failure. Shutting down.");
return;
}
......
......@@ -22,8 +22,8 @@ import java.lang.reflect.Method;
import org.skywalking.apm.agent.core.context.ContextManager;
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
public class TraceContextInterceptor implements StaticMethodsAroundInterceptor {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册