org.apache.log4j.HTMLLayout Java Examples

The following examples show how to use org.apache.log4j.HTMLLayout. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SyslogAppenderTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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));
}
 
Example #2
Source File: HtmlLogFile.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
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;
}
 
Example #3
Source File: AbstractScriptRunner.java    From sailfish-core with Apache License 2.0 3 votes vote down vote up
private Logger createScriptLogger(ScriptSettings scriptSettings, String reportFolder) throws IOException, WorkspaceStructureException {
    org.apache.log4j.Logger scriptLogger = org.apache.log4j.Logger.getLogger("TestScript_" + RandomStringUtils.randomAlphanumeric(10));
    scriptLogger.removeAllAppenders();

    PatternLayout layout = new PatternLayout(scriptSettings.getFileLayout());

    RollingFileAppender fileAppender = new RollingFileAppender(layout, workspaceDispatcher.createFile(FolderType.REPORT, true, reportFolder, "script.log").getPath());

    fileAppender.setName("TESTSCRIPTFILEAPPENDER");

    fileAppender.setThreshold(Level.toLevel(scriptSettings.getFileLoggerLevel()));

    fileAppender.activateOptions();

    HTMLLayout htmlLayout = new HTMLLayout();

    RollingFileAppender htmlFileAppender = new RollingFileAppender(htmlLayout, workspaceDispatcher.createFile(FolderType.REPORT, true, reportFolder, "scriptlog.html").getPath());

    htmlFileAppender.setName("HTMLTESTSCRIPTFILEAPPENDER");

    htmlFileAppender.setThreshold(Level.toLevel(scriptSettings.getFileLoggerLevel()));

    PatternLayout conLayout = new PatternLayout(scriptSettings.getConsoleLayout());

    ConsoleAppender conAppender = new ConsoleAppender(conLayout);
    conAppender.setThreshold(Level.toLevel(scriptSettings.getConsoleLoggerLevel()));
    conAppender.activateOptions();

    scriptLogger.addAppender(fileAppender);
    scriptLogger.addAppender(conAppender);
    scriptLogger.addAppender(htmlFileAppender);

    return LoggerFactory.getLogger(scriptLogger.getName());
}