static { Appender appender = null; PatternLayout layout = new PatternLayout(); layout.setConversionPattern("%d{yyyy/MM/dd HH:mm:ss.SSS} %p [%c{1}] [%x] %m%n"); try { appender = new org.apache.log4j.FileAppender(layout, "zoie-test-log.log"); } catch (IOException e) { e.printStackTrace(); } org.apache.log4j.BasicConfigurator.configure(appender); }
private static void initLogger() { RollingFileAppender appender = new RollingFileAppender(); PatternLayout layout = new PatternLayout(); layout.setConversionPattern("%p [%d{ISO8601}] [%F:%L] %m%n"); appender.setName("R"); appender.setFile("igv.log"); appender.setThreshold(Level.ALL); appender.setMaxFileSize("10KB"); appender.setMaxBackupIndex(1); appender.setAppend(true); appender.activateOptions(); appender.setLayout(layout); Logger.getRootLogger().addAppender(appender); }
/** {@inheritDoc} */ @Override public void testStopped(final Result result) { LOGGER.info("result is : ---- " + result.getAssert() + " ----"); long cost = System.currentTimeMillis() - currentTestStartTime; ResultItem item = new ResultItem(); item.id = currentTestCase.getId(); item.res = result.getAssert(); item.notes = result.getReason(); item.costInMS = cost; item.spec = currentTestCase.getSpecSection(); item.desc = currentTestCase.getDescription(); String prefix = "" + currentTestCase.getId() + "."; if (result.getAssert() != TestResult.SKIP) { final PatternLayout layout = new PatternLayout(); layout.setConversionPattern("%6r [%-20.20t] %-5p %30.30c (%6L) %x %m%n"); final File remoteFile = new File(reportDir, prefix + "remote.log"); final File localFile = new File(reportDir, prefix + "local.log"); final File resourceFile = new File(reportDir, prefix + "resource.log"); try { remoteAppender.writeToFile(layout, remoteFile); item.remoteLogURI = "file:" + remoteFile.getName(); boolean hasError = remoteAppender.hasErrorLevelEvent(); item.hasErrorLevelLog = Boolean.toString(hasError); localAppender.writeToFile(layout, localFile); item.localLogURI = "file:" + localFile.getName(); resourceAppender.writeToFile(layout, resourceFile); item.resourceLog = filterReturn(resourceAppender); } catch (IOException e) { LOGGER.error(e.getMessage(), e); return; } } reportDoc.add(item); currentTestCase = null; // write to file. final File report = new File(reportDir, reportName); try { LOGGER.info("writing report to: '" + report.getCanonicalPath() + "'"); writeReport(report); } catch (IOException e) { LOGGER.error("error writing the report", e); } }
public static Logger getLogger(String categroy, String name) { Logger logger = Logger.getLogger(name); logger.removeAllAppenders(); logger.setAdditivity(false); FileAppender appender = null; PatternLayout layout = new PatternLayout(); layout.setConversionPattern("[%p][%d{yyyy-MM-dd HH:mm:ss}] %m%n"); try { appender = new DailyRollingFileAppender( layout, String.format("/data/applogs/%s/%s.log", categroy, name), "yyyy-MM-dd"); appender.setEncoding("UTF-8"); appender.activateOptions(); } catch (IOException e) { throw new RuntimeException("LogUtil fail.", e); } logger.addAppender(appender); logger.setLevel(Level.INFO); return logger; }
@Override protected void append(LoggingEvent arg0) { myTextArea.append(layout.format(arg0)); }
public void setConversionPattern(String conversionPattern) { super.setConversionPattern(conversionPattern); }