/** * Reads the log file and returns the data.<p> * * @param moduleName the module name * @return the log contents * * @throws IOException if something goes wrong */ public synchronized byte[] readLog(String moduleName) throws IOException { File logFile = getLogFile(moduleName); if (logFile.exists()) { return CmsFileUtil.readFile(logFile); } else { return new byte[] {}; } }
/** * Logs a module action.<p> * * @param moduleName the module name * @param action the action * @param ok true if the action was successful */ public synchronized void log(String moduleName, Action action, boolean ok) { if (moduleName == null) { return; } SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT_STRING); String now = format.format(new Date()); String message = now + " " + action.getPrintName() + " " + (ok ? "0" : "1"); log(moduleName, message); }
byte[] data = OpenCms.getModuleManager().getImportExportRepository().getModuleLog().readLog(moduleName); resultFile.setContents(data); return resultFile;
m_moduleLog.log(moduleName, Action.exportModule, !failed);
/** * Logs a message for the given module.<p> * * @param moduleName the module name * @param message the message to log */ private synchronized void log(String moduleName, String message) { // We re-open the file every time. This should be OK performance-wise, since modules are usually not // imported/exported/deleted so frequently that this would matter. File logFile = getLogFile(moduleName); logFile.getParentFile().mkdirs(); FileOutputStream out = null; PrintStream ps = null; try { out = new FileOutputStream(logFile, true); // open file with append=true ps = new PrintStream(out); ps.println(message); } catch (IOException e) { LOG.error(e.getLocalizedMessage(), e); } finally { if (ps != null) { ps.close(); } } } }
throw e; } finally { m_moduleLog.log(moduleName, Action.importModule, ok);
m_moduleLog.log(moduleName, Action.deleteModule, ok);