Search in sources :

Example 1 with LogProfileInfo

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());
            }
        }
    }
}
Also used : ProfileElementInstance(com.creditease.uav.profiling.spi.ProfileElementInstance) LogProfileInfo(com.creditease.uav.profiling.handlers.log.LogProfileInfo) LinkedList(java.util.LinkedList)

Example 2 with LogProfileInfo

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);
    }
}
Also used : LoggerRepository(org.apache.log4j.spi.LoggerRepository) InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) Enumeration(java.util.Enumeration) Logger(org.apache.log4j.Logger) LogProfileInfo(com.creditease.uav.profiling.handlers.log.LogProfileInfo) LinkedList(java.util.LinkedList)

Example 3 with LogProfileInfo

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);
    }
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) FileAppender(ch.qos.logback.core.FileAppender) HashMap(java.util.HashMap) HTMLLayout(ch.qos.logback.classic.html.HTMLLayout) PatternLayout(ch.qos.logback.classic.PatternLayout) TTLLLayout(ch.qos.logback.classic.layout.TTLLLayout) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LogProfileInfo(com.creditease.uav.profiling.handlers.log.LogProfileInfo) XMLLayout(ch.qos.logback.classic.log4j.XMLLayout) LayoutWrappingEncoder(ch.qos.logback.core.encoder.LayoutWrappingEncoder)

Example 4 with 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);
    }
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) LogProfileInfo(com.creditease.uav.profiling.handlers.log.LogProfileInfo) LinkedList(java.util.LinkedList)

Example 5 with LogProfileInfo

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);
    }
}
Also used : Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) FileAppender(org.apache.log4j.FileAppender) HashMap(java.util.HashMap) HTMLLayout(org.apache.log4j.HTMLLayout) PatternLayout(org.apache.log4j.PatternLayout) LogProfileInfo(com.creditease.uav.profiling.handlers.log.LogProfileInfo) SimpleLayout(org.apache.log4j.SimpleLayout) TTCCLayout(org.apache.log4j.TTCCLayout) HTMLLayout(org.apache.log4j.HTMLLayout) SimpleLayout(org.apache.log4j.SimpleLayout) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) TTCCLayout(org.apache.log4j.TTCCLayout)

Aggregations

LogProfileInfo (com.creditease.uav.profiling.handlers.log.LogProfileInfo)5 LinkedList (java.util.LinkedList)3 InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)2 HashMap (java.util.HashMap)2 Logger (ch.qos.logback.classic.Logger)1 LoggerContext (ch.qos.logback.classic.LoggerContext)1 PatternLayout (ch.qos.logback.classic.PatternLayout)1 HTMLLayout (ch.qos.logback.classic.html.HTMLLayout)1 TTLLLayout (ch.qos.logback.classic.layout.TTLLLayout)1 XMLLayout (ch.qos.logback.classic.log4j.XMLLayout)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 Appender (ch.qos.logback.core.Appender)1 FileAppender (ch.qos.logback.core.FileAppender)1 LayoutWrappingEncoder (ch.qos.logback.core.encoder.LayoutWrappingEncoder)1 ProfileElementInstance (com.creditease.uav.profiling.spi.ProfileElementInstance)1 Enumeration (java.util.Enumeration)1 Appender (org.apache.log4j.Appender)1 FileAppender (org.apache.log4j.FileAppender)1 HTMLLayout (org.apache.log4j.HTMLLayout)1 Layout (org.apache.log4j.Layout)1