@Override protected void initializeAtStartup(final File file) { // rotate on every startup if (file.exists() && rotateAtStartup) { final File backup = new File(file.getParentFile(), file.getName() + OLD_FILE_FORMATTER.format(new Date())); try { rename(file, backup); } catch (IOException e) { throw ControllerLogger.ROOT_LOGGER.couldNotBackUp(e, file.getAbsolutePath(), backup.getAbsolutePath()); } } }
boolean isDifferent(AuditLogHandler other){ if (other instanceof FileAuditLogHandler == false){ return true; } FileAuditLogHandler otherHandler = (FileAuditLogHandler)other; if (!name.equals(otherHandler.name)){ return true; } if (!getFormatterName().equals(otherHandler.getFormatterName())) { return true; } if (!path.equals(otherHandler.path)){ return true; } if (!compare(relativeTo, otherHandler.relativeTo)){ return true; } return false; }
private void rename(File file, File to) throws IOException { if (!file.renameTo(to) && file.exists()) { copyFile(file, to); file.delete(); } } }
private static FileAuditLogHandler createFileAuditLogHandler(final PathManagerService pathManager, final OperationContext context, final ModelNode operation) throws OperationFailedException { final String name = Util.getNameFromAddress(operation.require(ModelDescriptionConstants.OP_ADDR)); final ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS).getModel(); final String relativeTo = model.hasDefined(RELATIVE_TO.getName()) ? RELATIVE_TO.resolveModelAttribute(context, model).asString() : null; final String path = PATH.resolveModelAttribute(context, model).asString(); final String formatterName = FORMATTER.resolveModelAttribute(context, model).asString(); final int maxFailureCount = MAX_FAILURE_COUNT.resolveModelAttribute(context, model).asInt(); final boolean rotateAtStartup = ROTATE_AT_STARTUP.resolveModelAttribute(context, model).asBoolean(); return new FileAuditLogHandler(name, formatterName, maxFailureCount, pathManager, path, relativeTo, rotateAtStartup); }
private static FileAuditLogHandler createFileAuditLogHandler(final PathManagerService pathManager, final OperationContext context, final ModelNode operation) throws OperationFailedException { final String name = Util.getNameFromAddress(operation.require(ModelDescriptionConstants.OP_ADDR)); final ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS).getModel(); final String relativeTo = model.hasDefined(RELATIVE_TO.getName()) ? RELATIVE_TO.resolveModelAttribute(context, model).asString() : null; final String path = PATH.resolveModelAttribute(context, model).asString(); final String formatterName = FORMATTER.resolveModelAttribute(context, model).asString(); final int maxFailureCount = MAX_FAILURE_COUNT.resolveModelAttribute(context, model).asInt(); final boolean rotateAtStartup = ROTATE_AT_STARTUP.resolveModelAttribute(context, model).asBoolean(); return new FileAuditLogHandler(name, formatterName, maxFailureCount, pathManager, path, relativeTo, rotateAtStartup); }
@Override protected void initializeAtStartup(final File file) { // rotate on every startup if (file.exists() && rotateAtStartup) { final File backup = new File(file.getParentFile(), file.getName() + OLD_FILE_FORMATTER.format(new Date())); try { rename(file, backup); } catch (IOException e) { throw ControllerLogger.ROOT_LOGGER.couldNotBackUp(e, file.getAbsolutePath(), backup.getAbsolutePath()); } } }
@Override void initialize() { if (file != null){ return; } File file = new File(pathManager.resolveRelativePathEntry(path, relativeTo)); if (file.exists() && file.isDirectory()) { throw ControllerMessages.MESSAGES.resolvedFileDoesNotExistOrIsDirectory(file); } File parent = file.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } if (file.exists()) { File backup = new File(file.getParentFile(), file.getName() + OLD_FILE_FORMATTER.format(new Date())); try { rename(file, backup); } catch (IOException e) { throw ControllerMessages.MESSAGES.couldNotBackUp(e, file.getAbsolutePath(), backup.getAbsolutePath()); } } try { file.createNewFile(); } catch (IOException e){ throw new RuntimeException(e); } this.file = file; }