public void tuneAuditLog()

in priam/src/main/java/com/netflix/priam/tuner/dse/AuditLogTunerLog4J.java [57:121]


    public void tuneAuditLog() {
        BufferedWriter writer = null;
        try {
            final File srcFile = new File(config.getCassHome() + AUDIT_LOG_FILE);
            final List<String> lines = Files.readLines(srcFile, Charset.defaultCharset());
            final File backupFile =
                    new File(
                            config.getCassHome()
                                    + AUDIT_LOG_FILE
                                    + "."
                                    + System.currentTimeMillis());
            Files.move(srcFile, backupFile);
            writer = Files.newWriter(srcFile, Charset.defaultCharset());

            String loggerPrefix = "log4j.appender.";
            try {
                loggerPrefix += findAuditLoggerName(lines);
            } catch (IllegalStateException ise) {
                logger.warn(
                        "cannot locate "
                                + PRIMARY_AUDIT_LOG_ENTRY
                                + " property, will ignore any audit log updating");
                return;
            }

            for (String line : lines) {
                if (line.contains(loggerPrefix)
                        || line.contains(PRIMARY_AUDIT_LOG_ENTRY)
                        || line.contains(AUDIT_LOG_ADDITIVE_ENTRY)) {
                    if (dseConfig.isAuditLogEnabled()) {
                        // first, check to see if we need to uncomment the line
                        while (line.startsWith("#")) {
                            line = line.substring(1);
                        }

                        // next, check if we need to change the prop's value
                        if (line.contains("ActiveCategories")) {
                            final String cats =
                                    Joiner.on(",").join(dseConfig.getAuditLogCategories());
                            line = line.substring(0, line.indexOf("=") + 1).concat(cats);
                        } else if (line.contains("ExemptKeyspaces")) {
                            line =
                                    line.substring(0, line.indexOf("=") + 1)
                                            .concat(dseConfig.getAuditLogExemptKeyspaces());
                        }
                    } else {
                        if (line.startsWith("#")) {
                            // make sure there's only one # at the beginning of the line
                            while (line.charAt(1) == '#') line = line.substring(1);
                        } else {
                            line = "#" + line;
                        }
                    }
                }
                writer.append(line);
                writer.newLine();
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("Unable to read " + AUDIT_LOG_FILE, e);

        } finally {
            FileUtils.closeQuietly(writer);
        }
    }