kumaab commented on code in PR #439: URL: https://github.com/apache/ranger/pull/439#discussion_r1877256945
########## agents-audit/src/main/java/org/apache/ranger/audit/utils/RangerJSONAuditWriter.java: ########## @@ -133,113 +143,92 @@ public PrintWriter run() throws Exception { } @Override - public boolean log(Collection<String> events) throws Exception { + public boolean log(Collection<String> events) throws Exception { return logJSON(events); } - synchronized public boolean logAsFile(final File file) throws Exception { - boolean ret = false; - if (logger.isDebugEnabled()) { - logger.debug("UGI=" + MiscUtil.getUGILoginUser() - + ". Will write to HDFS file=" + currentFileName); - } - Boolean retVal = MiscUtil.executePrivilegedAction(new PrivilegedExceptionAction<Boolean>() { - @Override - public Boolean run() throws Exception { - boolean ret = logFileToHDFS(file); - return Boolean.valueOf(ret); - }; - }); - ret = retVal.booleanValue(); - logger.info("Flushing HDFS audit File :" + file.getAbsolutePath() + file.getName()); - return ret; - } - @Override public boolean logFile(File file) throws Exception { return logAsFile(file); } - synchronized public PrintWriter getLogFileStream() throws Exception { - if (!enableAuditFilePeriodicRollOver) { - // when periodic rollover is enabled closing of file is done by the file rollover monitoring task and hence don't need to - // close the file inline with audit logging. - closeFileIfNeeded(); - } - // Either there are no open log file or the previous one has been rolled over - PrintWriter logWriter = createWriter(); - return logWriter; - } - - - public void flush() { - if (logger.isDebugEnabled()) { - logger.debug("==> JSONWriter.flush() called. name=" + auditProviderName); - } - super.flush(); - if (logger.isDebugEnabled()) { - logger.debug("<== JSONWriter.flush()"); - } - } - @Override public void start() { // nothing to start } @Override - synchronized public void stop() { - if (logger.isDebugEnabled()) { - logger.debug("==> JSONWriter.stop()"); - } + public synchronized void stop() { + logger.debug("==> JSONWriter.stop()"); + if (logWriter != null) { try { logWriter.flush(); logWriter.close(); } catch (Throwable t) { - logger.error("Error on closing log writter. Exception will be ignored. name=" - + auditProviderName + ", fileName=" + currentFileName); + logger.error("Error on closing log writter. Exception will be ignored. name={}, fileName={}", auditProviderName, currentFileName); } + logWriter = null; - ostream = null; + ostream = null; } - if (logger.isDebugEnabled()) { - logger.debug("<== JSONWriter.stop()"); + + logger.debug("<== JSONWriter.stop()"); + } + + public synchronized boolean logAsFile(final File file) throws Exception { + logger.debug("UGI={}. Will write to HDFS file={}", MiscUtil.getUGILoginUser(), currentFileName); + + boolean ret = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<Boolean>) () -> logFileToHDFS(file)); + + logger.info("Flushing HDFS audit File :{}{}", file.getAbsolutePath(), file.getName()); + + return ret; + } + + public synchronized PrintWriter getLogFileStream() throws Exception { + if (!enableAuditFilePeriodicRollOver) { + // when periodic rollover is enabled closing of file is done by the file rollover monitoring task and hence don't need to + // close the file inline with audit logging. + closeFileIfNeeded(); } + + // Either there are no open log file or the previous one has been rolled over + return createWriter(); } private void startAuditFilePeriodicRollOverTask() { ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(new AuditFilePeriodicRollOverTaskThreadFactory()); - if (logger.isDebugEnabled()) { - logger.debug("HDFSAuditDestination.startAuditFilePeriodicRollOverTask() strated.." + "Audit File rollover happens every " + rolloverPeriod ); - } + logger.debug("HDFSAuditDestination.startAuditFilePeriodicRollOverTask() strated.." + "Audit File rollover happens every {}", rolloverPeriod); Review Comment: nit: the sentences can be combined. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@ranger.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org