Search in sources :

Example 1 with HTMLLayout

use of org.apache.log4j.HTMLLayout in project Lucee by lucee.

the class Log4jUtil method getLayout.

public static final Layout getLayout(ClassDefinition cd, Map<String, String> layoutArgs) {
    if (layoutArgs == null)
        layoutArgs = new HashMap<String, String>();
    // Layout
    Layout layout = null;
    if (cd != null && cd.hasClass()) {
        // Classic Layout
        if (ClassicLayout.class.getName().equalsIgnoreCase(cd.getClassName()))
            layout = new ClassicLayout();
        else // HTML Layout
        if (HTMLLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
            HTMLLayout html = new HTMLLayout();
            layout = html;
            // Location Info
            Boolean locInfo = Caster.toBoolean(layoutArgs.get("locationinfo"), null);
            if (locInfo != null)
                html.setLocationInfo(locInfo.booleanValue());
            else
                locInfo = Boolean.FALSE;
            layoutArgs.put("locationinfo", locInfo.toString());
            // Title
            String title = Caster.toString(layoutArgs.get("title"), "");
            if (!StringUtil.isEmpty(title, true))
                html.setTitle(title);
            layoutArgs.put("title", title);
        } else // XML Layout
        if (XMLLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
            XMLLayout xml = new XMLLayout();
            layout = xml;
            // Location Info
            Boolean locInfo = Caster.toBoolean(layoutArgs.get("locationinfo"), null);
            if (locInfo != null)
                xml.setLocationInfo(locInfo.booleanValue());
            else
                locInfo = Boolean.FALSE;
            layoutArgs.put("locationinfo", locInfo.toString());
            // Properties
            Boolean props = Caster.toBoolean(layoutArgs.get("properties"), null);
            if (props != null)
                xml.setProperties(props.booleanValue());
            else
                props = Boolean.FALSE;
            layoutArgs.put("properties", props.toString());
        } else // Pattern Layout
        if (PatternLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
            PatternLayout patt = new PatternLayout();
            layout = patt;
            // pattern
            String pattern = Caster.toString(layoutArgs.get("pattern"), null);
            if (!StringUtil.isEmpty(pattern, true))
                patt.setConversionPattern(pattern);
            else {
                patt.setConversionPattern(DEFAULT_PATTERN);
                layoutArgs.put("pattern", DEFAULT_PATTERN);
            }
        } else // class defintion
        {
            Object obj = ClassUtil.loadInstance(cd.getClazz(null), null, null);
            if (obj instanceof Layout) {
                layout = (Layout) obj;
                Iterator<Entry<String, String>> it = layoutArgs.entrySet().iterator();
                Entry<String, String> e;
                while (it.hasNext()) {
                    e = it.next();
                    try {
                        Reflector.callSetter(obj, e.getKey(), e.getValue());
                    } catch (PageException e1) {
                        // TODO log
                        SystemOut.printDate(e1);
                    }
                }
            }
        }
    }
    if (layout != null)
        return layout;
    return new ClassicLayout();
}
Also used : PageException(lucee.runtime.exp.PageException) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) HTMLLayout(org.apache.log4j.HTMLLayout) ClassicLayout(lucee.commons.io.log.log4j.layout.ClassicLayout) XMLLayout(org.apache.log4j.xml.XMLLayout) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) HTMLLayout(org.apache.log4j.HTMLLayout) PatternLayout(org.apache.log4j.PatternLayout) ClassicLayout(lucee.commons.io.log.log4j.layout.ClassicLayout) Iterator(java.util.Iterator) XMLLayout(org.apache.log4j.xml.XMLLayout)

Example 2 with HTMLLayout

use of org.apache.log4j.HTMLLayout 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)

Example 3 with HTMLLayout

use of org.apache.log4j.HTMLLayout in project jop by jop-devel.

the class LogConfig method setReportLoggers.

@SuppressWarnings({ "ResultOfMethodCallIgnored" })
public void setReportLoggers(File errorLog, File infoLog) throws IOException {
    this.errorLog = errorLog;
    this.infoLog = infoLog;
    if (errorLog != null) {
        errorLog.delete();
        FileAppender eapp = new FileAppender(new HTMLLayout(), errorLog.getPath());
        eapp.setName("AERROR");
        eapp.setThreshold(Level.WARN);
        Logger.getRootLogger().addAppender(eapp);
    }
    if (infoLog != null) {
        infoLog.delete();
        FileAppender iapp = new FileAppender(new HTMLLayout(), infoLog.getPath());
        // TODO maybe make level of info logger configurable (one of INFO, DEBUG, ALL)?
        iapp.setThreshold(Level.ALL);
        iapp.setName("AINFO");
        Logger.getRootLogger().addAppender(iapp);
    }
}
Also used : FileAppender(org.apache.log4j.FileAppender) HTMLLayout(org.apache.log4j.HTMLLayout)

Aggregations

HTMLLayout (org.apache.log4j.HTMLLayout)3 HashMap (java.util.HashMap)2 FileAppender (org.apache.log4j.FileAppender)2 Layout (org.apache.log4j.Layout)2 PatternLayout (org.apache.log4j.PatternLayout)2 LogProfileInfo (com.creditease.uav.profiling.handlers.log.LogProfileInfo)1 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 ClassicLayout (lucee.commons.io.log.log4j.layout.ClassicLayout)1 PageException (lucee.runtime.exp.PageException)1 Appender (org.apache.log4j.Appender)1 SimpleLayout (org.apache.log4j.SimpleLayout)1 TTCCLayout (org.apache.log4j.TTCCLayout)1 XMLLayout (org.apache.log4j.xml.XMLLayout)1