@Override public InputStream getLog(String suiteId, String jobId) throws IOException { if (jobId == null) { return getLog(suiteId); } InputStream fullLog = getLog(suiteId); if (fullLog != null) { return new FilteredInputStream( getLog(suiteId), new StartWithFilter(jobId)); } return null; }
@Override public final InputStream getLog(final String suiteId) throws IOException { File logFile = getLogFile(suiteId); if (logFile != null && logFile.exists()) { return new FileInputStream(logFile); } return null; } @Override
private ILogManager resolveLogManager(ILogManager configLogManager) { ILogManager lm = configLogManager; if (lm == null) { lm = new FileLogManager(workdir); } LOG.info("JEF log manager is : " + lm.getClass().getSimpleName()); return lm; } private IJobStatusStore resolveJobStatusStore(
@Override public final void backup(final String suiteId, final Date backupDate) throws IOException { resolveDirsIfNeeded(); String date = new SimpleDateFormat( "yyyyMMddHHmmssSSSS").format(backupDate); File progressFile = getLogFile(suiteId); File backupDir = FileUtil.createDateDirs( new File(logdirBackupBase), backupDate); backupDir = new File(backupDir, "logs"); if (!backupDir.exists()) { try { FileUtils.forceMkdir(backupDir); } catch (IOException e) { throw new JEFException("Cannot create backup directory: " + backupDir, e); } } File backupFile = new File( backupDir + "/" + date + "__" + FileUtil.toSafeFileName(suiteId) + LOG_SUFFIX); if (progressFile.exists()) { FileUtil.moveFile(progressFile, backupFile); } }
Appender appender = getLogManager().createAppender(getId()); appender.setLayout(new ThreadSafeLayout(appender.getLayout()));
/** * Gets the log file used by this log manager. * @param suiteId log file suiteId * @return log file */ public File getLogFile(final String suiteId) { if (suiteId == null) { return null; } resolveDirsIfNeeded(); return new File(logdirLatest + "/" + FileUtil.toSafeFileName(suiteId) + LOG_SUFFIX); }
@Override public void loadFromXML(Reader in) throws IOException { XMLConfiguration xml = XMLConfigurationUtil.newXMLConfiguration(in); setLogDirectory(xml.getString("logDir", logdir)); }
/** * Gets the last lines from a suite log. * @param suite the suite to extract the log from * @param lineQty the number of lines to retrieve * @return string representation of log last lines * @throws IOException problem getting lines */ @SuppressWarnings("nls") protected final String getLogTail(final JobSuite suite, final int lineQty) throws IOException { StringBuffer logTail = new StringBuffer(); String[] lines = IOUtil.tail( suite.getLogManager().getLog(suite.getId()), lineQty); if (lines.length == 0) { logTail.append("*** No log found. ***\n"); } else { for (int i = 0; i < lines.length; i++) { String line = lines[i]; logTail.append(line); logTail.append('\n'); } } return logTail.toString(); } }
private void writeJobSuiteIndex(JobSuiteStatusSnapshot statusTree) throws IOException { File indexFile = getSuiteIndexFile(); StringWriter out = new StringWriter(); out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); out.write("<suite-index>"); //--- Log Manager --- out.flush(); getLogManager().saveToXML(out); //--- JobStatusSerializer --- out.flush(); getJobStatusStore().saveToXML(out); //--- Job Status --- writeJobId(out, statusTree, statusTree.getRoot()); out.write("</suite-index>"); out.flush(); // Using RandomAccessFile since evidence has shown it is better at // dealing with files/locks in a way that cause less/no errors. try (RandomAccessFile ras = new RandomAccessFile(indexFile, "rwd"); FileChannel channel = ras.getChannel(); FileLock lock = channel.lock()) { ras.writeUTF(out.toString()); } }
getLogManager().backup(getId(), backupDate);
suiteConfig.setLogManager(new FileLogManager(collConfig.getLogsDir())); suiteConfig.setJobStatusStore( new FileJobStatusStore(collConfig.getProgressDir()));
@Override public final Appender createAppender(final String suiteId) throws IOException { resolveDirsIfNeeded(); return new FileAppender(new PatternLayout(LAYOUT_PATTERN), logdirLatest + "/" + FileUtil.toSafeFileName(suiteId) + LOG_SUFFIX); }