1.提交日志功能以及测试类 2. 将SDK切换成新的日志功能
This commit is contained in:
parent
f286cbd781
commit
aa5ae55145
|
|
@ -2,13 +2,13 @@ package com.ai.cloud.skywalking.buffer;
|
|||
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.conf.Constants;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
import com.ai.cloud.skywalking.selfexamination.HeathReading;
|
||||
import com.ai.cloud.skywalking.selfexamination.SDKHealthCollector;
|
||||
import com.ai.cloud.skywalking.sender.DataSenderFactoryWithBalance;
|
||||
import com.ai.cloud.skywalking.util.AtomicRangeInteger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import static com.ai.cloud.skywalking.conf.Config.Buffer.BUFFER_MAX_SIZE;
|
||||
import static com.ai.cloud.skywalking.conf.Config.Consumer.*;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
package com.ai.cloud.skywalking.buffer;
|
||||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import static com.ai.cloud.skywalking.conf.Config.Buffer.POOL_SIZE;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ import static com.ai.cloud.skywalking.conf.Config.BuriedPoint.EXCLUSIVE_EXCEPTIO
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.ai.cloud.skywalking.api.IExceptionHandler;
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
|
||||
public class ApplicationExceptionHandler implements IExceptionHandler {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
package com.ai.cloud.skywalking.buriedpoint;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.ai.cloud.skywalking.api.IBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.buffer.ContextBuffer;
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
import com.ai.cloud.skywalking.model.EmptyContextData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
package com.ai.cloud.skywalking.buriedpoint;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.ai.cloud.skywalking.api.IBuriedPointReceiver;
|
||||
import com.ai.cloud.skywalking.buffer.ContextBuffer;
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
package com.ai.cloud.skywalking.buriedpoint;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.ai.cloud.skywalking.api.IBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.buffer.ContextBuffer;
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
import com.ai.cloud.skywalking.model.EmptyContextData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
package com.ai.cloud.skywalking.buriedpoint;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.ai.cloud.skywalking.api.IBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.buffer.ContextBuffer;
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
import com.ai.cloud.skywalking.model.EmptyContextData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
|
|
|
|||
|
|
@ -71,9 +71,20 @@ public class Config {
|
|||
|
||||
public static long RETRY_FIND_CONNECTION_SENDER = 1000;
|
||||
}
|
||||
|
||||
|
||||
public static class HealthCollector {
|
||||
// 默认健康检查上报时间
|
||||
public static long REPORT_INTERVAL = 5 * 60 * 1000L;
|
||||
// 默认健康检查上报时间
|
||||
public static long REPORT_INTERVAL = 5 * 60 * 1000L;
|
||||
}
|
||||
|
||||
public static class Logging {
|
||||
// log文件名
|
||||
public static String LOG_FILE_NAME = "skywalking-api.log";
|
||||
// log文件路径
|
||||
public static String LOG_FILE_PATH = "/home/xin/tmp";
|
||||
// 最大文件大小
|
||||
public static int MAX_LOG_FILE_LENGTH = 3 * 1024 * 1024;
|
||||
// skywalking 系统错误文件日志
|
||||
public static String SYSTEM_ERROR_LOG_FILE_NAME = "skywalking-api-error.log";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
package com.ai.cloud.skywalking.conf;
|
||||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
|
||||
import static com.ai.cloud.skywalking.conf.Config.SkyWalking.AUTH_OVERRIDE;
|
||||
import static com.ai.cloud.skywalking.conf.Config.SkyWalking.AUTH_SYSTEM_ENV_NAME;
|
||||
|
||||
|
|
@ -10,9 +13,6 @@ import java.lang.reflect.Modifier;
|
|||
import java.util.LinkedList;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class ConfigInitializer {
|
||||
private static Logger logger = LogManager.getLogger(ConfigInitializer.class);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
package com.ai.cloud.skywalking.logging;
|
||||
|
||||
public interface IFileWriter {
|
||||
void write(String message);
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.ai.cloud.skywalking.logging;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-23.
|
||||
*/
|
||||
public class LogManager {
|
||||
|
||||
public static Logger getLogger(Class toBeLoggerClass) {
|
||||
return new Logger(toBeLoggerClass);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
package com.ai.cloud.skywalking.logging;
|
||||
|
||||
|
||||
import com.ai.cloud.skywalking.util.LoggingUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-23.
|
||||
*/
|
||||
public class Logger {
|
||||
|
||||
private Class toBeLoggerClass;
|
||||
|
||||
public Logger(Class toBeLoggerClass) {
|
||||
this.toBeLoggerClass = toBeLoggerClass;
|
||||
}
|
||||
|
||||
public void logger(String level, String message, Throwable e) {
|
||||
Throwable dummyException = new Throwable();
|
||||
StackTraceElement locations[] = dummyException.getStackTrace();
|
||||
|
||||
if (locations != null && locations.length > 2) {
|
||||
SyncFileWriter.instance().write(formatMessage(level, message, locations[2]));
|
||||
}
|
||||
|
||||
if (e != null) {
|
||||
SyncFileWriter.instance().write(LoggingUtil.fetchThrowableStack(e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void error(String message, Throwable e) {
|
||||
logger(ERROR, message, e);
|
||||
}
|
||||
|
||||
public void error(String message) {
|
||||
error(message, null);
|
||||
}
|
||||
|
||||
public void warn(String message, Object... parameters) {
|
||||
String tmpMessage = replaceParameter(message, parameters);
|
||||
logger(WARN, tmpMessage, null);
|
||||
}
|
||||
|
||||
|
||||
public void debug(String message) {
|
||||
logger(DEBUG, message, null);
|
||||
}
|
||||
|
||||
public void debug(Object message) {
|
||||
debug(message.toString());
|
||||
}
|
||||
|
||||
public void info(Object message) {
|
||||
info(message.toString());
|
||||
}
|
||||
|
||||
public void info(String message) {
|
||||
logger(INFO, message, null);
|
||||
}
|
||||
|
||||
public void debug(String message, Object... parameters) {
|
||||
debug(replaceParameter(message, parameters));
|
||||
}
|
||||
|
||||
public void error(String message, Object[] parameters, Throwable throwable) {
|
||||
logger(ERROR, replaceParameter(message, parameters), throwable);
|
||||
}
|
||||
|
||||
public void info(String message, Object paramter) {
|
||||
info(replaceParameter(message, new Object[]{paramter}));
|
||||
}
|
||||
|
||||
|
||||
private String replaceParameter(String message, Object... parameters) {
|
||||
int startSize = 0;
|
||||
int parametersIndex = 0;
|
||||
int index = -1;
|
||||
String tmpMessage = message;
|
||||
while ((index = message.indexOf("{}", startSize)) != -1) {
|
||||
if (parametersIndex >= parameters.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
tmpMessage = tmpMessage.replaceFirst("\\{\\}", parameters[parametersIndex++].toString());
|
||||
startSize = index + 2;
|
||||
}
|
||||
return tmpMessage;
|
||||
}
|
||||
|
||||
|
||||
private String formatMessage(String level, String message, StackTraceElement caller) {
|
||||
return level + " " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " "
|
||||
+ caller.getClassName() + "." + caller.getMethodName() + "(" + caller.getFileName() + ":" + caller.getLineNumber() + ") " + message;
|
||||
}
|
||||
|
||||
|
||||
private static final String ERROR = "ERROR";
|
||||
private static final String WARN = "WARN";
|
||||
private static final String DEBUG = "DEBUG";
|
||||
private static final String INFO = "INFO";
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.ai.cloud.skywalking.logging;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-23.
|
||||
*/
|
||||
public class LoggerManager {
|
||||
|
||||
public static Logger getLog(Class toBeClass) {
|
||||
return new Logger(toBeClass);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
package com.ai.cloud.skywalking.logging;
|
||||
|
||||
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.util.LoggingUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import static com.ai.cloud.skywalking.conf.Config.Logging.LOG_FILE_NAME;
|
||||
import static com.ai.cloud.skywalking.conf.Config.Logging.LOG_FILE_PATH;
|
||||
|
||||
public class SyncFileWriter implements IFileWriter {
|
||||
|
||||
private static SyncFileWriter writer;
|
||||
private FileOutputStream os;
|
||||
private int bufferSize;
|
||||
private static final Object lock = new Object();
|
||||
|
||||
private SyncFileWriter() {
|
||||
try {
|
||||
os = new FileOutputStream(new File(LOG_FILE_PATH,
|
||||
LOG_FILE_NAME), true);
|
||||
bufferSize = Long.valueOf(new File(LOG_FILE_PATH, LOG_FILE_NAME).length()).intValue();
|
||||
} catch (IOException e) {
|
||||
writeErrorLog(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static IFileWriter instance() {
|
||||
if (writer == null) {
|
||||
writer = new SyncFileWriter();
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
|
||||
|
||||
public void write(String message) {
|
||||
writeLogRecord(message);
|
||||
switchLogFileIfNecessary();
|
||||
}
|
||||
|
||||
private void writeLogRecord(String message) {
|
||||
try {
|
||||
os.write(message.getBytes());
|
||||
os.write("\n".getBytes());
|
||||
bufferSize += message.length();
|
||||
} catch (IOException e) {
|
||||
writeErrorLog(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void switchLogFileIfNecessary() {
|
||||
if (bufferSize > Config.Logging.MAX_LOG_FILE_LENGTH) {
|
||||
synchronized (lock) {
|
||||
if (bufferSize > Config.Logging.MAX_LOG_FILE_LENGTH) {
|
||||
try {
|
||||
closeInputStream();
|
||||
renameLogFile();
|
||||
revertInputStream();
|
||||
} catch (IOException e) {
|
||||
writeErrorLog(e);
|
||||
}
|
||||
bufferSize = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void revertInputStream() throws FileNotFoundException {
|
||||
os = new FileOutputStream(new File(Config.Logging.LOG_FILE_PATH,
|
||||
Config.Logging.LOG_FILE_NAME), true);
|
||||
}
|
||||
|
||||
private void renameLogFile() {
|
||||
new File(Config.Logging.LOG_FILE_PATH, Config.Logging.LOG_FILE_NAME)
|
||||
.renameTo(new File(Config.Logging.LOG_FILE_PATH,
|
||||
Config.Logging.LOG_FILE_NAME +
|
||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
|
||||
}
|
||||
|
||||
private void closeInputStream() throws IOException {
|
||||
this.os.flush();
|
||||
this.os.close();
|
||||
}
|
||||
|
||||
|
||||
private void writeErrorLog(Throwable e) {
|
||||
FileOutputStream fileOutputStream = null;
|
||||
try {
|
||||
File file = new File(Config.Logging.LOG_FILE_PATH, Config.Logging.SYSTEM_ERROR_LOG_FILE_NAME);
|
||||
fileOutputStream = new FileOutputStream(file, true);
|
||||
fileOutputStream.write(("Failed to init sync File Writer.\n" + LoggingUtil.fetchThrowableStack(e)).getBytes());
|
||||
} catch (Exception e1) {
|
||||
System.err.print(LoggingUtil.fetchThrowableStack(e1));
|
||||
} finally {
|
||||
if (fileOutputStream != null) {
|
||||
try {
|
||||
fileOutputStream.close();
|
||||
} catch (IOException e1) {
|
||||
System.err.print(LoggingUtil.fetchThrowableStack(e1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,58 +1,56 @@
|
|||
package com.ai.cloud.skywalking.plugin;
|
||||
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import net.bytebuddy.pool.TypePool;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import net.bytebuddy.pool.TypePool;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
|
||||
public class PluginBootstrap {
|
||||
private static Logger logger = LogManager.getLogger(PluginBootstrap.class);
|
||||
|
||||
public static TypePool CLASS_TYPE_POOL = null;
|
||||
private static Logger logger = LogManager.getLogger(PluginBootstrap.class);
|
||||
|
||||
public void start() {
|
||||
if (!AuthDesc.isAuth()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CLASS_TYPE_POOL = TypePool.Default.ofClassPath();
|
||||
public static TypePool CLASS_TYPE_POOL = null;
|
||||
|
||||
PluginResourcesResolver resolver = new PluginResourcesResolver();
|
||||
List<URL> resources = resolver.getResources();
|
||||
public void start() {
|
||||
if (!AuthDesc.isAuth()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (resources == null || resources.size() == 0) {
|
||||
logger.info("no plugin files (skywalking-plugin.properties) found, continue to start application.");
|
||||
return;
|
||||
}
|
||||
CLASS_TYPE_POOL = TypePool.Default.ofClassPath();
|
||||
|
||||
for (URL pluginUrl : resources) {
|
||||
try {
|
||||
PluginCfg.CFG.load(pluginUrl.openStream());
|
||||
} catch (Throwable t) {
|
||||
logger.error("plugin [{}] init failure.", pluginUrl, t);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> pluginClassList = PluginCfg.CFG
|
||||
PluginResourcesResolver resolver = new PluginResourcesResolver();
|
||||
List<URL> resources = resolver.getResources();
|
||||
|
||||
if (resources == null || resources.size() == 0) {
|
||||
logger.info("no plugin files (skywalking-plugin.properties) found, continue to start application.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (URL pluginUrl : resources) {
|
||||
try {
|
||||
PluginCfg.CFG.load(pluginUrl.openStream());
|
||||
} catch (Throwable t) {
|
||||
logger.error("plugin [{}] init failure.", new Object[]{pluginUrl}, t);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> pluginClassList = PluginCfg.CFG
|
||||
.getPluginClassList();
|
||||
|
||||
for (String pluginClassName : pluginClassList) {
|
||||
try {
|
||||
logger.debug("prepare to enhance class by plugin {}.",
|
||||
pluginClassName);
|
||||
IPlugin plugin = (IPlugin) Class.forName(
|
||||
pluginClassName).newInstance();
|
||||
plugin.define();
|
||||
logger.debug("prepare to enhance class by plugin {}.",
|
||||
pluginClassName);
|
||||
IPlugin plugin = (IPlugin) Class.forName(
|
||||
pluginClassName).newInstance();
|
||||
plugin.define();
|
||||
} catch (Throwable t) {
|
||||
logger.error("prepare to enhance class by plugin [{}] failure.",
|
||||
pluginClassName, t);
|
||||
new Object[]{pluginClassName}, t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
package com.ai.cloud.skywalking.plugin;
|
||||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class PluginResourcesResolver {
|
||||
private static Logger logger = LogManager.getLogger(PluginResourcesResolver.class);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
package com.ai.cloud.skywalking.plugin;
|
||||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* 替代应用函数的main函数入口,确保在程序入口处运行 <br/>
|
||||
* 用于替代-javaagent的另一种模式 <br/>
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor;
|
||||
|
||||
import static com.ai.cloud.skywalking.plugin.PluginBootstrap.CLASS_TYPE_POOL;
|
||||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.dynamic.ClassFileLocator;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
|
||||
import net.bytebuddy.pool.TypePool.Resolution;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.IPlugin;
|
||||
import com.ai.cloud.skywalking.plugin.PluginException;
|
||||
import com.ai.cloud.skywalking.util.StringUtil;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor.enhance;
|
||||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import net.bytebuddy.implementation.bind.annotation.AllArguments;
|
||||
import net.bytebuddy.implementation.bind.annotation.FieldProxy;
|
||||
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
|
||||
import net.bytebuddy.implementation.bind.annotation.This;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
|
||||
public class ClassConstructorInterceptor {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ package com.ai.cloud.skywalking.plugin.interceptor.enhance;
|
|||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.any;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
import net.bytebuddy.implementation.MethodDelegation;
|
||||
|
|
@ -10,9 +13,6 @@ import net.bytebuddy.implementation.bind.annotation.FieldProxy;
|
|||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.PluginException;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.AbstractClassEnhancePluginDefine;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.EnhanceException;
|
||||
|
|
|
|||
|
|
@ -1,76 +1,68 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor.enhance;
|
||||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import net.bytebuddy.implementation.bind.annotation.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import net.bytebuddy.implementation.bind.annotation.AllArguments;
|
||||
import net.bytebuddy.implementation.bind.annotation.FieldValue;
|
||||
import net.bytebuddy.implementation.bind.annotation.Origin;
|
||||
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
|
||||
import net.bytebuddy.implementation.bind.annotation.SuperCall;
|
||||
import net.bytebuddy.implementation.bind.annotation.This;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
|
||||
/**
|
||||
* 类方法拦截、控制器
|
||||
*
|
||||
* @author wusheng
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public class ClassInstanceMethodsInterceptor {
|
||||
private static Logger logger = LogManager
|
||||
.getLogger(ClassInstanceMethodsInterceptor.class);
|
||||
private static Logger logger = LogManager
|
||||
.getLogger(ClassInstanceMethodsInterceptor.class);
|
||||
|
||||
private IntanceMethodsAroundInterceptor interceptor;
|
||||
private IntanceMethodsAroundInterceptor interceptor;
|
||||
|
||||
public ClassInstanceMethodsInterceptor(IntanceMethodsAroundInterceptor interceptor) {
|
||||
this.interceptor = interceptor;
|
||||
}
|
||||
public ClassInstanceMethodsInterceptor(IntanceMethodsAroundInterceptor interceptor) {
|
||||
this.interceptor = interceptor;
|
||||
}
|
||||
|
||||
@RuntimeType
|
||||
public Object intercept(
|
||||
@This Object obj,
|
||||
@AllArguments Object[] allArguments,
|
||||
@Origin Method method,
|
||||
@SuperCall Callable<?> zuper,
|
||||
@FieldValue(ClassEnhancePluginDefine.contextAttrName) EnhancedClassInstanceContext instanceContext)
|
||||
throws Exception {
|
||||
InstanceMethodInvokeContext interceptorContext = new InstanceMethodInvokeContext(obj,
|
||||
method.getName(), allArguments);
|
||||
MethodInterceptResult result = new MethodInterceptResult();
|
||||
try {
|
||||
interceptor.beforeMethod(instanceContext, interceptorContext, result);
|
||||
} catch (Throwable t) {
|
||||
logger.error("class[{}] before method[{}] intercept failue:{}",
|
||||
obj.getClass(), method.getName(), t.getMessage(), t);
|
||||
}
|
||||
if(!result.isContinue()){
|
||||
return result._ret();
|
||||
}
|
||||
|
||||
Object ret = null;
|
||||
try {
|
||||
ret = zuper.call();
|
||||
} catch(Throwable t){
|
||||
try {
|
||||
interceptor.handleMethodException(t, instanceContext, interceptorContext, ret);
|
||||
} catch (Throwable t2) {
|
||||
logger.error("class[{}] handle method[{}] exception failue:{}",
|
||||
obj.getClass(), method.getName(), t2.getMessage(), t2);
|
||||
}
|
||||
throw t;
|
||||
}finally {
|
||||
try {
|
||||
ret = interceptor.afterMethod(instanceContext, interceptorContext, ret);
|
||||
} catch (Throwable t) {
|
||||
logger.error("class[{}] after method[{}] intercept failue:{}",
|
||||
obj.getClass(), method.getName(), t.getMessage(), t);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@RuntimeType
|
||||
public Object intercept(
|
||||
@This Object obj,
|
||||
@AllArguments Object[] allArguments,
|
||||
@Origin Method method,
|
||||
@SuperCall Callable<?> zuper,
|
||||
@FieldValue(ClassEnhancePluginDefine.contextAttrName) EnhancedClassInstanceContext instanceContext)
|
||||
throws Exception {
|
||||
InstanceMethodInvokeContext interceptorContext = new InstanceMethodInvokeContext(obj,
|
||||
method.getName(), allArguments);
|
||||
MethodInterceptResult result = new MethodInterceptResult();
|
||||
try {
|
||||
interceptor.beforeMethod(instanceContext, interceptorContext, result);
|
||||
} catch (Throwable t) {
|
||||
logger.error("class[{}] before method[{}] intercept failue:{}",
|
||||
new Object[]{obj.getClass(), method.getName(), t.getMessage()}, t);
|
||||
}
|
||||
if (!result.isContinue()) {
|
||||
return result._ret();
|
||||
}
|
||||
|
||||
Object ret = null;
|
||||
try {
|
||||
ret = zuper.call();
|
||||
} catch (Throwable t) {
|
||||
try {
|
||||
interceptor.handleMethodException(t, instanceContext, interceptorContext, ret);
|
||||
} catch (Throwable t2) {
|
||||
logger.error("class[{}] handle method[{}] exception failue:{}",
|
||||
new Object[]{obj.getClass(), method.getName(), t2.getMessage()}, t2);
|
||||
}
|
||||
throw t;
|
||||
} finally {
|
||||
try {
|
||||
ret = interceptor.afterMethod(instanceContext, interceptorContext, ret);
|
||||
} catch (Throwable t) {
|
||||
logger.error("class[{}] after method[{}] intercept failue:{}",
|
||||
new Object[]{obj.getClass(), method.getName(), t.getMessage()}, t);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@ import java.util.Arrays;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.util.BuriedPointMachineUtil;
|
||||
|
||||
public class SDKHealthCollector extends Thread {
|
||||
|
|
|
|||
|
|
@ -1,32 +1,22 @@
|
|||
package com.ai.cloud.skywalking.sender;
|
||||
|
||||
import static com.ai.cloud.skywalking.conf.Config.Sender.CHECKER_THREAD_WAIT_INTERVAL;
|
||||
import static com.ai.cloud.skywalking.conf.Config.Sender.CLOSE_SENDER_COUNTDOWN;
|
||||
import static com.ai.cloud.skywalking.conf.Config.Sender.CONNECT_PERCENT;
|
||||
import static com.ai.cloud.skywalking.conf.Config.Sender.RETRY_GET_SENDER_WAIT_INTERVAL;
|
||||
import static com.ai.cloud.skywalking.conf.Config.Sender.SWITCH_SENDER_INTERVAL;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.selfexamination.HeathReading;
|
||||
import com.ai.cloud.skywalking.selfexamination.SDKHealthCollector;
|
||||
import com.ai.cloud.skywalking.util.StringUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static com.ai.cloud.skywalking.conf.Config.Sender.*;
|
||||
|
||||
public class DataSenderFactoryWithBalance {
|
||||
|
||||
private static Logger logger = LogManager.getLogger(DataSenderFactoryWithBalance.class);
|
||||
private static Logger logger = LogManager.getLogger(DataSenderFactoryWithBalance.class);
|
||||
// unUsedServerAddress存放没有使用的服务器地址,
|
||||
private static List<InetSocketAddress> unusedServerAddresses = new ArrayList<InetSocketAddress>();
|
||||
|
||||
|
|
@ -171,7 +161,7 @@ public class DataSenderFactoryWithBalance {
|
|||
try {
|
||||
Thread.sleep(CLOSE_SENDER_COUNTDOWN);
|
||||
} catch (InterruptedException e) {
|
||||
logger.log(Level.ALL, "Sleep Failed");
|
||||
logger.error("Sleep Failed", e);
|
||||
}
|
||||
toBeSwitchSender.close();
|
||||
unusedServerAddresses.remove(tmpSender
|
||||
|
|
@ -184,10 +174,10 @@ public class DataSenderFactoryWithBalance {
|
|||
sleepTime = 0;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
SDKHealthCollector.getCurrentHeathReading(null).updateData(HeathReading.ERROR, "DataSenderChecker running failed:" + e.getMessage());
|
||||
SDKHealthCollector.getCurrentHeathReading(null).updateData(HeathReading.ERROR, "DataSenderChecker running failed:" + e.getMessage());
|
||||
logger.error("DataSenderChecker running failed", e);
|
||||
} finally{
|
||||
SDKHealthCollector.getCurrentHeathReading(null).updateData(HeathReading.INFO, "using available DataSender connect to: " + listUsingServers());
|
||||
} finally {
|
||||
SDKHealthCollector.getCurrentHeathReading(null).updateData(HeathReading.INFO, "using available DataSender connect to: " + listUsingServers());
|
||||
}
|
||||
|
||||
sleepTime += CHECKER_THREAD_WAIT_INTERVAL;
|
||||
|
|
@ -205,7 +195,7 @@ public class DataSenderFactoryWithBalance {
|
|||
DataSender result = null;
|
||||
int index = 0;
|
||||
|
||||
if (unusedServerAddresses.size() > 1){
|
||||
if (unusedServerAddresses.size() > 1) {
|
||||
index = ThreadLocalRandom.current().nextInt(0,
|
||||
unusedServerAddresses.size());
|
||||
}
|
||||
|
|
@ -232,19 +222,19 @@ public class DataSenderFactoryWithBalance {
|
|||
}
|
||||
|
||||
public static void unRegister(DataSender socket) {
|
||||
socket.setStatus(DataSender.SenderStatus.FAILED);
|
||||
socket.setStatus(DataSender.SenderStatus.FAILED);
|
||||
}
|
||||
|
||||
private static String listUsingServers(){
|
||||
StringBuilder usingAddrDesc = new StringBuilder();
|
||||
if(usingDataSender.size() > 0){
|
||||
for(DataSender sender : usingDataSender){
|
||||
if(usingAddrDesc.length() > 0){
|
||||
usingAddrDesc.append(",");
|
||||
}
|
||||
usingAddrDesc.append(sender.getServerAddr().toString());
|
||||
}
|
||||
}
|
||||
return usingAddrDesc.toString();
|
||||
|
||||
private static String listUsingServers() {
|
||||
StringBuilder usingAddrDesc = new StringBuilder();
|
||||
if (usingDataSender.size() > 0) {
|
||||
for (DataSender sender : usingDataSender) {
|
||||
if (usingAddrDesc.length() > 0) {
|
||||
usingAddrDesc.append(",");
|
||||
}
|
||||
usingAddrDesc.append(sender.getServerAddr().toString());
|
||||
}
|
||||
}
|
||||
return usingAddrDesc.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package com.ai.cloud.skywalking.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-24.
|
||||
*/
|
||||
public class LoggingUtil {
|
||||
public static String fetchThrowableStack(Throwable e) {
|
||||
ByteArrayOutputStream buf = new ByteArrayOutputStream();
|
||||
e.printStackTrace(new java.io.PrintWriter(buf, true));
|
||||
String expMessage = buf.toString();
|
||||
try {
|
||||
buf.close();
|
||||
} catch (IOException e1) {
|
||||
System.err.println("Failed to close throwable stack stream.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return expMessage;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package test.ai.cloud.logging;
|
||||
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LoggingTest {
|
||||
|
||||
Logger logger = LogManager.getLogger(LoggingTest.class);
|
||||
|
||||
@Test
|
||||
public void testNormalLogging() {
|
||||
logger.debug("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorLogging() {
|
||||
logger.error("Hello World", new RuntimeException("Failed message"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFile() {
|
||||
Config.Logging.MAX_LOG_FILE_LENGTH = 2400;
|
||||
logger.error("Hello World", new RuntimeException("Failed message"));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue