use of com.creditease.uav.profiling.handlers.log.LogProfileInfo in project uavstack by uavorg.
the class LogProfileHandler method profileFromLogProfileInfo.
/**
* profileFromLogProfileInfo
*
* @param elem
* @param ic
* @param appid
*/
private void profileFromLogProfileInfo(ProfileElement elem, InterceptContext ic, String appid) {
@SuppressWarnings("unchecked") LinkedList<LogProfileInfo> list = (LinkedList<LogProfileInfo>) ic.get(HookConstants.LOG_PROFILE_LIST);
if (list == null || list.size() == 0) {
this.logger.warn("Profile:LOGS FAILs as LogProfileInfo List is null or its size 0", null);
return;
}
// Log Source 1: AUTO Profiling
for (LogProfileInfo logProfileInfo : list) {
if (appid.equals(logProfileInfo.getAppId())) {
ProfileElementInstance pei = elem.getInstance(logProfileInfo.getLogType().toString());
String logPath = logProfileInfo.getFilePath();
// set the log file path
if (null != logPath) {
pei.setValue(logPath, logProfileInfo.getAttributes());
}
}
}
}
use of com.creditease.uav.profiling.handlers.log.LogProfileInfo in project uavstack by uavorg.
the class Log4jHookProxy method figureOutLog4jConfig.
/**
* figure out the log4j's configuration: for example, appenders' file path, buff io, etc...
*
* @param context
* @param webapploader
*/
@SuppressWarnings({ "rawtypes", "static-access" })
private void figureOutLog4jConfig(HookContext context, ClassLoader webapploader) {
Logger logger4j = Logger.getLogger(Log4jHookProxy.class);
InterceptContext interceptContext = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
if (interceptContext == null) {
logger.warn("No InterceptContext available, can't figure out Log4j configuration.", null);
return;
}
@SuppressWarnings("unchecked") LinkedList<LogProfileInfo> list = (LinkedList<LogProfileInfo>) interceptContext.get(HookConstants.LOG_PROFILE_LIST);
if (null == list) {
list = new LinkedList<LogProfileInfo>();
interceptContext.put(HookConstants.LOG_PROFILE_LIST, list);
}
String appid = (String) (interceptContext.get(InterceptConstants.CONTEXTPATH));
// figureout root logger
figureoutLogConfiguration(logger4j.getRootLogger(), list, appid);
// figureour norootlogger
LoggerRepository lr = null;
try {
lr = logger4j.getLoggerRepository();
} catch (NoSuchMethodError err) {
// for log4j-over-slf4j, doesn't have this method
return;
}
Enumeration logEnum = lr.getCurrentLoggers();
while (logEnum != null && logEnum.hasMoreElements()) {
Logger sLogger = (Logger) logEnum.nextElement();
figureoutLogConfiguration(sLogger, list, appid);
}
}
use of com.creditease.uav.profiling.handlers.log.LogProfileInfo in project uavstack by uavorg.
the class LogBackHookProxy method figureoutLogConfiguration.
private void figureoutLogConfiguration(Logger Logger, LinkedList<LogProfileInfo> list, String appid) {
Iterator<Appender<ILoggingEvent>> appenders = Logger.iteratorForAppenders();
while (appenders != null && appenders.hasNext()) {
LogProfileInfo logProfileInfo = new LogProfileInfo();
if (appid != null) {
logProfileInfo.setAppId(appid);
}
logProfileInfo.setLogType(LogProfileInfo.LogType.Log4j);
Map<String, String> attributes = new HashMap<String, String>();
attributes.put(LogProfileInfo.ENGINE, "logback");
Appender<ILoggingEvent> appender = appenders.next();
if (!(appender instanceof FileAppender<?>)) {
continue;
}
FileAppender<ILoggingEvent> fileAppender = (FileAppender<ILoggingEvent>) appender;
@SuppressWarnings("rawtypes") LayoutWrappingEncoder encoder = (LayoutWrappingEncoder) fileAppender.getEncoder();
Layout<?> layout = encoder.getLayout();
if (null != layout) {
if (layout instanceof PatternLayout) {
PatternLayout patternLayout = (PatternLayout) encoder.getLayout();
attributes.put(LogProfileInfo.PATTERN, patternLayout.getPattern());
} else if (layout instanceof HTMLLayout) {
attributes.put(LogProfileInfo.PATTERN, "HTMLLayout");
} else if (layout instanceof XMLLayout) {
attributes.put(LogProfileInfo.PATTERN, "XMLLayout");
} else if (layout instanceof TTLLLayout) {
attributes.put(LogProfileInfo.PATTERN, "TTCCLayout");
}
}
logProfileInfo.setFilePath(fileAppender.getFile());
logProfileInfo.setAttributes(attributes);
list.add(logProfileInfo);
}
}
use of com.creditease.uav.profiling.handlers.log.LogProfileInfo in project uavstack by uavorg.
the class LogBackHookProxy method figureOutLogBackConfig.
/**
* figure out the logback's configuration: for example, appenders' file path, buff io, etc...
*
* @param context
* @param webapploader
*/
private void figureOutLogBackConfig(HookContext context, ClassLoader webapploader) {
Logger logback = (Logger) LoggerFactory.getLogger(LogBackHookProxy.class);
InterceptContext interceptContext = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
if (interceptContext == null) {
logback.warn("No InterceptContext available, can't figure out LogBack configuration.");
return;
}
@SuppressWarnings("unchecked") LinkedList<LogProfileInfo> list = (LinkedList<LogProfileInfo>) interceptContext.get(HookConstants.LOG_PROFILE_LIST);
if (null == list) {
list = new LinkedList<LogProfileInfo>();
interceptContext.put(HookConstants.LOG_PROFILE_LIST, list);
}
String appid = (String) (interceptContext.get(InterceptConstants.CONTEXTPATH));
// figureour all loggers
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
List<ch.qos.logback.classic.Logger> loggers = loggerContext.getLoggerList();
for (Logger logger : loggers) {
figureoutLogConfiguration(logger, list, appid);
}
}
use of com.creditease.uav.profiling.handlers.log.LogProfileInfo in project uavstack by uavorg.
the class Log4jHookProxy method figureoutLogConfiguration.
@SuppressWarnings("unchecked")
private void figureoutLogConfiguration(Logger Logger, LinkedList<LogProfileInfo> list, String appid) {
Enumeration<Appender> appenders = Logger.getAllAppenders();
while (appenders != null && appenders.hasMoreElements()) {
LogProfileInfo logProfileInfo = new LogProfileInfo();
if (appid != null) {
logProfileInfo.setAppId(appid);
}
logProfileInfo.setLogType(LogProfileInfo.LogType.Log4j);
Map<String, String> attributes = new HashMap<String, String>();
attributes.put(LogProfileInfo.ENGINE, "log4j");
Appender appender = appenders.nextElement();
if (!(appender instanceof FileAppender)) {
continue;
}
FileAppender fileAppender = (FileAppender) appender;
Layout layout = fileAppender.getLayout();
if (null != layout) {
if (layout instanceof PatternLayout) {
PatternLayout patternLayout = (PatternLayout) fileAppender.getLayout();
attributes.put(LogProfileInfo.PATTERN, patternLayout.getConversionPattern());
} else if (layout instanceof HTMLLayout) {
attributes.put(LogProfileInfo.PATTERN, "HTMLLayout");
} else if (layout instanceof SimpleLayout) {
attributes.put(LogProfileInfo.PATTERN, "SimpleLayout");
} else if (layout instanceof TTCCLayout) {
attributes.put(LogProfileInfo.PATTERN, "TTCCLayout");
}
}
boolean useBuffIO = fileAppender.getBufferedIO();
if (useBuffIO == true) {
attributes.put(LogProfileInfo.BUFFER_SIZE, String.valueOf(fileAppender.getBufferSize()));
attributes.put(LogProfileInfo.BUFFRT_IO, String.valueOf(useBuffIO));
}
logProfileInfo.setFilePath(fileAppender.getFile());
logProfileInfo.setAttributes(attributes);
list.add(logProfileInfo);
}
}
Aggregations