java类org.apache.log4j.HTMLLayout的实例源码

SyslogAppenderTest.java 文件源码 项目:cacheonix-core 阅读 28 收藏 0 点赞 0 评论 0
/**
 * Tests that any header or footer in layout is sent.
 * @throws Exception if exception during test.
 */
public void testLayoutHeader() throws Exception {
    DatagramSocket ds = new DatagramSocket();
    ds.setSoTimeout(2000);

  SyslogAppender appender = new SyslogAppender();
  appender.setSyslogHost("localhost:" + ds.getLocalPort());
  appender.setName("name");
  appender.setHeader(false);
  HTMLLayout pl = new HTMLLayout();
  appender.setLayout(pl);
  appender.activateOptions();

  Logger l = Logger.getRootLogger();
  l.addAppender(appender);
  l.info("Hello, World");
  appender.close();
  String[] s = new String[3];
  byte[] buf = new byte[1000];
  for(int i = 0; i < 3; i++) {
      DatagramPacket p = new DatagramPacket(buf, 0, buf.length);
      ds.receive(p);
      s[i] = new String(p.getData(), 0, p.getLength());
  }
  ds.close();
  assertEquals("<14><!DOCTYPE", s[0].substring(0,13));
  assertEquals("<14></table>", s[2].substring(0,12));
}
Log4jUtil.java 文件源码 项目:Lucee 阅读 26 收藏 0 点赞 0 评论 0
public static ClassDefinition<Layout> layoutClassDefintion(String className) {
    if("classic".equalsIgnoreCase(className))return new ClassDefinitionImpl( ClassicLayout.class);
    if("html".equalsIgnoreCase(className))return new ClassDefinitionImpl( HTMLLayout.class);
    if("xml".equalsIgnoreCase(className))return new ClassDefinitionImpl( XMLLayout.class);
    if("pattern".equalsIgnoreCase(className))return new ClassDefinitionImpl( PatternLayout.class);

    return new ClassDefinitionImpl( className);
}
ApplicationContextSupport.java 文件源码 项目:Lucee 阅读 25 收藏 0 点赞 0 评论 0
public static ClassDefinition toClassDefinition(Struct sct, ClassDefinition defaultValue, boolean isAppender, boolean isLayout) {
    if(sct==null) return defaultValue;

    // class
    String className=Caster.toString(sct.get("class",null),null);
    if(StringUtil.isEmpty(className)) return defaultValue;

    if(isAppender) {
        if("console".equalsIgnoreCase(className))   return new ClassDefinitionImpl( ConsoleAppender.class);
        if("resource".equalsIgnoreCase(className))  return new ClassDefinitionImpl( RollingResourceAppender.class);
        if("datasource".equalsIgnoreCase(className))return new ClassDefinitionImpl( DatasourceAppender.class);
    }
    else if(isLayout) {
        if("classic".equalsIgnoreCase(className))return new ClassDefinitionImpl( ClassicLayout.class);
        if("html".equalsIgnoreCase(className))return new ClassDefinitionImpl( HTMLLayout.class);
        if("xml".equalsIgnoreCase(className))return new ClassDefinitionImpl( XMLLayout.class);
        if("pattern".equalsIgnoreCase(className))return new ClassDefinitionImpl( PatternLayout.class);
    }

    // name
    String name=Caster.toString(sct.get("bundlename",null),null);
    if(StringUtil.isEmpty(name)) name=Caster.toString(sct.get("name",null),null);

    // version
    Version version=OSGiUtil.toVersion(Caster.toString(sct.get("bundleversion",null),null),null);
    if(version==null) version=OSGiUtil.toVersion(Caster.toString(sct.get("version",null),null),null);

    if(StringUtil.isEmpty(name)) return new ClassDefinitionImpl(className);

    return new ClassDefinitionImpl(null,className, name, version);
}
Job.java 文件源码 项目:ExpressZip 阅读 26 收藏 0 点赞 0 评论 0
public Job(ExportProps param, ExportOptionsViewComponent view) {
    jobParams = param;
    parent = view;

    url = view.getApplication().getMainWindow().getURL();
    if (exportDir == null) {
        exportDir = new File(ExpressZipApplication.Configuration.getProperty("exportdirectory"), jobParams.getJobName());
        exportDir.mkdir();
    }
    String JobRunID = String.format("%d", System.identityHashCode(this));
    logger = Logger.getLogger(JobRunID);
    logger.setAdditivity(false);
    try {
        outputLogFile = new File(exportDir, getLogName());
        outputLogAppender = new FileAppender(new HTMLLayout(), outputLogFile.getPath());
        logger.addAppender(outputLogAppender);
    } catch (IOException e) {
        BasicConfigurator.configure();
    }

    // Set up GeoTIFF writer compression and tiling
    geoTiffWPs = new GeoTiffWriteParams();
    geoTiffWPs.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT);
    geoTiffWPs.setCompressionType("LZW");
    geoTiffWPs.setCompressionQuality(0.75F);
    geoTiffWPs.setTilingMode(GeoTiffWriteParams.MODE_EXPLICIT);
    geoTiffWPs.setTiling(256, 256);
}
HtmlLogFile.java 文件源码 项目:olca-app 阅读 23 收藏 0 点赞 0 评论 0
private static WriterAppender createAppender(File logFile)
        throws IOException {
    HTMLLayout layout = new HTMLLayout();
    RollingFileAppender app = new RollingFileAppender(layout,
            logFile.getAbsolutePath(), true);
    app.setMaxFileSize("3MB");
    app.setMaxBackupIndex(3);
    return app;
}
Log4jHookProxy.java 文件源码 项目:uavstack 阅读 21 收藏 0 点赞 0 评论 0
@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);

    }
}
ConfigWebAdmin.java 文件源码 项目:Lucee4 阅读 22 收藏 0 点赞 0 评论 0
public void updateLogSettings(String name, Level level, String appenderClassName, Struct appenderArgs, String layoutClassName, Struct layoutArgs) throws PageException {
    checkWriteAccess();
    // TODO
    //boolean hasAccess=ConfigWebUtil.hasAccess(config,SecurityManagerImpl.TYPE_GATEWAY);
       // if(!hasAccess) throw new SecurityException("no access to update gateway entry");

       // check parameters
    name=name.trim();
    if(StringUtil.isEmpty(name))
           throw new ApplicationException("name can't be a empty value");

    if(StringUtil.isEmpty(appenderClassName))
        throw new ExpressionException("you must define appender class name");
    if(StringUtil.isEmpty(layoutClassName))
        throw new ExpressionException("you must define layout class name");

       try {
        ClassUtil.loadClass(appenderClassName);
        ClassUtil.loadClass(layoutClassName);

    }
       catch (ClassException e) {
           throw Caster.toPageException(e);
    }

       Element parent=_getRootElement("logging");

       // Update
       Element[] children = ConfigWebFactory.getChildren(parent,"logger");
       Element el=null;
        for(int i=0;i<children.length;i++) {
            String n=children[i].getAttribute("name");
            if(name.equalsIgnoreCase(n)) {
                el=children[i];
                break;
            }

        }
        // Insert
        if(el==null) {
        el=doc.createElement("logger");
        parent.appendChild(el);
        el.setAttribute("name",name);
        }

        // appender
        if(appenderClassName.equals(ConsoleAppender.class.getName())) appenderClassName="console";
        if(appenderClassName.equals(RollingResourceAppender.class.getName())) appenderClassName="resource";
        // layout
        if(layoutClassName.equals(PatternLayout.class.getName())) layoutClassName="pattern";
        if(layoutClassName.equals(ClassicLayout.class.getName())) layoutClassName="classic";
        if(layoutClassName.equals(HTMLLayout.class.getName())) layoutClassName="html";
        if(layoutClassName.equals(XMLLayout.class.getName())) layoutClassName="xml";

        el.setAttribute("level",level.toString());
        el.setAttribute("appender",appenderClassName);
        el.setAttribute("appender-arguments",toStringCSSStyle(appenderArgs));
    el.setAttribute("layout",layoutClassName);
    el.setAttribute("layout-arguments",toStringCSSStyle(layoutArgs));
}


问题


面经


文章

微信
公众号

扫码关注公众号