Return-Path: X-Original-To: apmail-argus-commits-archive@minotaur.apache.org Delivered-To: apmail-argus-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CC81E1776F for ; Sun, 5 Oct 2014 04:44:52 +0000 (UTC) Received: (qmail 53470 invoked by uid 500); 5 Oct 2014 04:44:52 -0000 Delivered-To: apmail-argus-commits-archive@argus.apache.org Received: (qmail 53450 invoked by uid 500); 5 Oct 2014 04:44:52 -0000 Mailing-List: contact commits-help@argus.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@argus.incubator.apache.org Delivered-To: mailing list commits@argus.incubator.apache.org Received: (qmail 53441 invoked by uid 99); 5 Oct 2014 04:44:52 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Oct 2014 04:44:52 +0000 X-ASF-Spam-Status: No, hits=-2000.6 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 05 Oct 2014 04:44:27 +0000 Received: (qmail 53386 invoked by uid 99); 5 Oct 2014 04:44:24 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Oct 2014 04:44:24 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 2E8891BB9A; Sun, 5 Oct 2014 04:44:24 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: madhan@apache.org To: commits@argus.incubator.apache.org Date: Sun, 05 Oct 2014 04:44:24 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: ARGUS-101: use Log4j instead of LogLog for debug tracing in classes that implement saving access audit logs to HDFS. X-Virus-Checked: Checked by ClamAV on apache.org Repository: incubator-argus Updated Branches: refs/heads/master d95b51934 -> 7a9ee4d12 ARGUS-101: use Log4j instead of LogLog for debug tracing in classes that implement saving access audit logs to HDFS. Project: http://git-wip-us.apache.org/repos/asf/incubator-argus/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-argus/commit/185ab086 Tree: http://git-wip-us.apache.org/repos/asf/incubator-argus/tree/185ab086 Diff: http://git-wip-us.apache.org/repos/asf/incubator-argus/diff/185ab086 Branch: refs/heads/master Commit: 185ab0862432060288c81aed419507e450e0bef2 Parents: 01fb970 Author: mneethiraj Authored: Sat Oct 4 12:16:48 2014 -0700 Committer: mneethiraj Committed: Sat Oct 4 12:16:48 2014 -0700 ---------------------------------------------------------------------- .../xasecure/audit/provider/DebugTracer.java | 10 +++ .../audit/provider/LocalFileLogBuffer.java | 88 ++++++++++---------- .../xasecure/audit/provider/Log4jTracer.java | 35 ++++++++ .../audit/provider/hdfs/HdfsAuditProvider.java | 15 +++- .../audit/provider/hdfs/HdfsLogDestination.java | 66 +++++++++------ 5 files changed, 144 insertions(+), 70 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/185ab086/agents-audit/src/main/java/com/xasecure/audit/provider/DebugTracer.java ---------------------------------------------------------------------- diff --git a/agents-audit/src/main/java/com/xasecure/audit/provider/DebugTracer.java b/agents-audit/src/main/java/com/xasecure/audit/provider/DebugTracer.java new file mode 100644 index 0000000..81994b7 --- /dev/null +++ b/agents-audit/src/main/java/com/xasecure/audit/provider/DebugTracer.java @@ -0,0 +1,10 @@ +package com.xasecure.audit.provider; + +public interface DebugTracer { + void debug(String msg); + void debug(String msg, Throwable excp); + void warn(String msg); + void warn(String msg, Throwable excp); + void error(String msg); + void error(String msg, Throwable excp); +} http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/185ab086/agents-audit/src/main/java/com/xasecure/audit/provider/LocalFileLogBuffer.java ---------------------------------------------------------------------- diff --git a/agents-audit/src/main/java/com/xasecure/audit/provider/LocalFileLogBuffer.java b/agents-audit/src/main/java/com/xasecure/audit/provider/LocalFileLogBuffer.java index f743cc3..b04b6a4 100644 --- a/agents-audit/src/main/java/com/xasecure/audit/provider/LocalFileLogBuffer.java +++ b/agents-audit/src/main/java/com/xasecure/audit/provider/LocalFileLogBuffer.java @@ -37,7 +37,6 @@ import java.util.Comparator; import java.util.TreeSet; import org.apache.hadoop.security.UserGroupInformation; -import org.apache.log4j.helpers.LogLog; public class LocalFileLogBuffer implements LogBuffer { @@ -49,6 +48,7 @@ public class LocalFileLogBuffer implements LogBuffer { private int mRolloverIntervalSeconds = 10 * 60; private String mArchiveDirectory = null; private int mArchiveFileCount = 10; + private DebugTracer mLogger = null; private Writer mWriter = null; private String mBufferFilename = null; @@ -57,7 +57,8 @@ public class LocalFileLogBuffer implements LogBuffer { private DestinationDispatcherThread mDispatcherThread = null; - public LocalFileLogBuffer() { + public LocalFileLogBuffer(DebugTracer tracer) { + mLogger = tracer; } public String getDirectory() { @@ -127,18 +128,18 @@ public class LocalFileLogBuffer implements LogBuffer { @Override public void start(LogDestination destination) { - LogLog.debug("==> LocalFileLogBuffer.start()"); + mLogger.debug("==> LocalFileLogBuffer.start()"); - mDispatcherThread = new DestinationDispatcherThread(this, destination); + mDispatcherThread = new DestinationDispatcherThread(this, destination, mLogger); mDispatcherThread.start(); - LogLog.debug("<== LocalFileLogBuffer.start()"); + mLogger.debug("<== LocalFileLogBuffer.start()"); } @Override public void stop() { - LogLog.debug("==> LocalFileLogBuffer.stop()"); + mLogger.debug("==> LocalFileLogBuffer.stop()"); DestinationDispatcherThread dispatcherThread = mDispatcherThread; mDispatcherThread = null; @@ -149,13 +150,13 @@ public class LocalFileLogBuffer implements LogBuffer { try { dispatcherThread.join(); } catch (InterruptedException e) { - LogLog.warn("LocalFileLogBuffer.stop(): failed in waiting for DispatcherThread", e); + mLogger.warn("LocalFileLogBuffer.stop(): failed in waiting for DispatcherThread", e); } } closeFile(); - LogLog.debug("<== LocalFileLogBuffer.stop()"); + mLogger.debug("<== LocalFileLogBuffer.stop()"); } @Override @@ -183,10 +184,10 @@ public class LocalFileLogBuffer implements LogBuffer { ret = true; } catch(IOException excp) { - LogLog.warn("LocalFileLogBuffer.add(): write failed", excp); + mLogger.warn("LocalFileLogBuffer.add(): write failed", excp); } } else { - LogLog.warn("LocalFileLogBuffer.add(): writer is null"); + mLogger.warn("LocalFileLogBuffer.add(): writer is null"); } return ret; @@ -198,7 +199,7 @@ public class LocalFileLogBuffer implements LogBuffer { } private synchronized void openFile() { - LogLog.debug("==> LocalFileLogBuffer.openFile()"); + mLogger.debug("==> LocalFileLogBuffer.openFile()"); closeFile(); @@ -224,20 +225,20 @@ public class LocalFileLogBuffer implements LogBuffer { mWriter = createWriter(ostream); if(mWriter != null) { - LogLog.debug("LocalFileLogBuffer.openFile(): opened file " + mBufferFilename); + mLogger.debug("LocalFileLogBuffer.openFile(): opened file " + mBufferFilename); mNextFlushTime = System.currentTimeMillis() + (mFlushIntervalSeconds * 1000L); } else { - LogLog.warn("LocalFileLogBuffer.openFile(): failed to open file for write " + mBufferFilename); + mLogger.warn("LocalFileLogBuffer.openFile(): failed to open file for write " + mBufferFilename); mBufferFilename = null; } - LogLog.debug("<== LocalFileLogBuffer.openFile()"); + mLogger.debug("<== LocalFileLogBuffer.openFile()"); } private synchronized void closeFile() { - LogLog.debug("==> LocalFileLogBuffer.closeFile()"); + mLogger.debug("==> LocalFileLogBuffer.closeFile()"); Writer writer = mWriter; @@ -248,7 +249,7 @@ public class LocalFileLogBuffer implements LogBuffer { writer.flush(); writer.close(); } catch(IOException excp) { - LogLog.warn("LocalFileLogBuffer: failed to close file " + mBufferFilename, excp); + mLogger.warn("LocalFileLogBuffer: failed to close file " + mBufferFilename, excp); } if(mDispatcherThread != null) { @@ -256,17 +257,17 @@ public class LocalFileLogBuffer implements LogBuffer { } } - LogLog.debug("<== LocalFileLogBuffer.closeFile()"); + mLogger.debug("<== LocalFileLogBuffer.closeFile()"); } private void rollover() { - LogLog.debug("==> LocalFileLogBuffer.rollover()"); + mLogger.debug("==> LocalFileLogBuffer.rollover()"); closeFile(); openFile(); - LogLog.debug("<== LocalFileLogBuffer.rollover()"); + mLogger.debug("<== LocalFileLogBuffer.rollover()"); } private void checkFileStatus() { @@ -282,7 +283,7 @@ public class LocalFileLogBuffer implements LogBuffer { mWriter.flush(); } catch (IOException excp) { - LogLog.warn("LocalFileLogBuffer: failed to flush to file " + mBufferFilename, excp); + mLogger.warn("LocalFileLogBuffer: failed to flush to file " + mBufferFilename, excp); } } } @@ -295,7 +296,7 @@ public class LocalFileLogBuffer implements LogBuffer { try { writer = new OutputStreamWriter(os, mEncoding); } catch(UnsupportedEncodingException excp) { - LogLog.warn("LocalFileLogBuffer: failed to create output writer for file " + mBufferFilename, excp); + mLogger.warn("LocalFileLogBuffer: failed to create output writer for file " + mBufferFilename, excp); } } @@ -333,13 +334,16 @@ class DestinationDispatcherThread extends Thread { private boolean mStopThread = false; private LocalFileLogBuffer mFileLogBuffer = null; private LogDestination mDestination = null; + private DebugTracer mLogger = null; private String mCurrentLogfile = null; private BufferedReader mReader = null; - public DestinationDispatcherThread(LocalFileLogBuffer fileLogBuffer, LogDestination destination) { + public DestinationDispatcherThread(LocalFileLogBuffer fileLogBuffer, LogDestination destination, DebugTracer tracer) { super(DestinationDispatcherThread.class.getSimpleName() + "-" + System.currentTimeMillis()); + mLogger = tracer; + mFileLogBuffer = fileLogBuffer; mDestination = destination; @@ -347,7 +351,7 @@ class DestinationDispatcherThread extends Thread { } public void addLogfile(String filename) { - LogLog.debug("==> DestinationDispatcherThread.addLogfile(" + filename + ")"); + mLogger.debug("==> DestinationDispatcherThread.addLogfile(" + filename + ")"); if(filename != null) { synchronized(mCompletedLogfiles) { @@ -356,7 +360,7 @@ class DestinationDispatcherThread extends Thread { } } - LogLog.debug("<== DestinationDispatcherThread.addLogfile(" + filename + ")"); + mLogger.debug("<== DestinationDispatcherThread.addLogfile(" + filename + ")"); } public void stopThread() { @@ -376,11 +380,11 @@ class DestinationDispatcherThread extends Thread { try { loginUser = UserGroupInformation.getLoginUser(); } catch (IOException excp) { - LogLog.error("DestinationDispatcherThread.run(): failed to get login user details. Audit files will not be sent to HDFS destination", excp); + mLogger.error("DestinationDispatcherThread.run(): failed to get login user details. Audit files will not be sent to HDFS destination", excp); } if(loginUser == null) { - LogLog.error("DestinationDispatcherThread.run(): failed to get login user. Audit files will not be sent to HDFS destination"); + mLogger.error("DestinationDispatcherThread.run(): failed to get login user. Audit files will not be sent to HDFS destination"); return; } @@ -408,7 +412,7 @@ class DestinationDispatcherThread extends Thread { try { mCompletedLogfiles.wait(pollIntervalInMs); } catch(InterruptedException excp) { - LogLog.warn("DestinationDispatcherThread.run(): failed to wait for log file", excp); + mLogger.warn("DestinationDispatcherThread.run(): failed to wait for log file", excp); } } @@ -424,7 +428,7 @@ class DestinationDispatcherThread extends Thread { } private void init() { - LogLog.debug("==> DestinationDispatcherThread.init()"); + mLogger.debug("==> DestinationDispatcherThread.init()"); String dirName = MiscUtil.replaceTokens(mFileLogBuffer.getDirectory(), 0); @@ -447,11 +451,11 @@ class DestinationDispatcherThread extends Thread { } } - LogLog.debug("<== DestinationDispatcherThread.init()"); + mLogger.debug("<== DestinationDispatcherThread.init()"); } private boolean sendCurrentFile() { - LogLog.debug("==> DestinationDispatcherThread.sendCurrentFile()"); + mLogger.debug("==> DestinationDispatcherThread.sendCurrentFile()"); boolean ret = false; @@ -480,7 +484,7 @@ class DestinationDispatcherThread extends Thread { archiveCurrentFile(); } - LogLog.debug("<== DestinationDispatcherThread.sendCurrentFile()"); + mLogger.debug("<== DestinationDispatcherThread.sendCurrentFile()"); return ret; } @@ -518,7 +522,7 @@ class DestinationDispatcherThread extends Thread { } } } catch (IOException excp) { - LogLog.warn("getNextStringifiedLog.getNextLog(): failed to read from file " + mCurrentLogfile, excp); + mLogger.warn("getNextStringifiedLog.getNextLog(): failed to read from file " + mCurrentLogfile, excp); } } @@ -526,7 +530,7 @@ class DestinationDispatcherThread extends Thread { } private void openCurrentFile() { - LogLog.debug("==> openCurrentFile(" + mCurrentLogfile + ")"); + mLogger.debug("==> openCurrentFile(" + mCurrentLogfile + ")"); if(mCurrentLogfile != null) { try { @@ -538,15 +542,15 @@ class DestinationDispatcherThread extends Thread { mReader = new BufferedReader(strReader); } } catch(FileNotFoundException excp) { - LogLog.warn("openNextFile(): error while opening file " + mCurrentLogfile, excp); + mLogger.warn("openNextFile(): error while opening file " + mCurrentLogfile, excp); } } - LogLog.debug("<== openCurrentFile(" + mCurrentLogfile + ")"); + mLogger.debug("<== openCurrentFile(" + mCurrentLogfile + ")"); } private void closeCurrentFile() { - LogLog.debug("==> closeCurrentFile(" + mCurrentLogfile + ")"); + mLogger.debug("==> closeCurrentFile(" + mCurrentLogfile + ")"); if(mReader != null) { try { @@ -557,7 +561,7 @@ class DestinationDispatcherThread extends Thread { } mReader = null; - LogLog.debug("<== closeCurrentFile(" + mCurrentLogfile + ")"); + mLogger.debug("<== closeCurrentFile(" + mCurrentLogfile + ")"); } private void archiveCurrentFile() { @@ -574,7 +578,7 @@ class DestinationDispatcherThread extends Thread { if(! logFile.renameTo(archiveFile)) { // TODO: renameTo() does not work in all cases. in case of failure, copy the file contents to the destination and delete the file - LogLog.warn("archiving failed to move file: " + mCurrentLogfile + " ==> " + archiveFilename); + mLogger.warn("archiving failed to move file: " + mCurrentLogfile + " ==> " + archiveFilename); } File archiveDir = new File(archiveDirName); @@ -597,13 +601,13 @@ class DestinationDispatcherThread extends Thread { for(int i = 0; i < numOfFilesToDelete; i++) { if(! files[i].delete()) { - LogLog.warn("archiving failed to delete file: " + files[i].getAbsolutePath()); + mLogger.warn("archiving failed to delete file: " + files[i].getAbsolutePath()); } } } } } catch(Exception excp) { - LogLog.warn("archiveCurrentFile(): faile to move " + mCurrentLogfile + " to archive location " + archiveFilename, excp); + mLogger.warn("archiveCurrentFile(): faile to move " + mCurrentLogfile + " to archive location " + archiveFilename, excp); } } mCurrentLogfile = null; @@ -619,7 +623,7 @@ class DestinationDispatcherThread extends Thread { try { reader = new InputStreamReader(iStr, encoding); } catch(UnsupportedEncodingException excp) { - LogLog.warn("createReader(): failed to create input reader.", excp); + mLogger.warn("createReader(): failed to create input reader.", excp); } } @@ -635,7 +639,7 @@ class DestinationDispatcherThread extends Thread { try { Thread.sleep(sleepTimeInMs); } catch(InterruptedException excp) { - LogLog.warn(onFailMsg, excp); + mLogger.warn(onFailMsg, excp); } } http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/185ab086/agents-audit/src/main/java/com/xasecure/audit/provider/Log4jTracer.java ---------------------------------------------------------------------- diff --git a/agents-audit/src/main/java/com/xasecure/audit/provider/Log4jTracer.java b/agents-audit/src/main/java/com/xasecure/audit/provider/Log4jTracer.java new file mode 100644 index 0000000..8c2cf91 --- /dev/null +++ b/agents-audit/src/main/java/com/xasecure/audit/provider/Log4jTracer.java @@ -0,0 +1,35 @@ +package com.xasecure.audit.provider; + +import org.apache.commons.logging.Log; + +public class Log4jTracer implements DebugTracer { + private Log mLogger = null; + + public Log4jTracer(Log logger) { + mLogger = logger; + } + + public void debug(String msg) { + mLogger.debug(msg); + } + + public void debug(String msg, Throwable excp) { + mLogger.debug(msg, excp); + } + + public void warn(String msg) { + mLogger.warn(msg); + } + + public void warn(String msg, Throwable excp) { + mLogger.warn(msg, excp); + } + + public void error(String msg) { + mLogger.error(msg); + } + + public void error(String msg, Throwable excp) { + mLogger.error(msg, excp); + } +} http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/185ab086/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsAuditProvider.java ---------------------------------------------------------------------- diff --git a/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsAuditProvider.java b/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsAuditProvider.java index 8087fe2..db94313 100644 --- a/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsAuditProvider.java +++ b/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsAuditProvider.java @@ -2,12 +2,18 @@ package com.xasecure.audit.provider.hdfs; import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import com.xasecure.audit.model.AuditEventBase; import com.xasecure.audit.provider.BufferedAuditProvider; +import com.xasecure.audit.provider.DebugTracer; import com.xasecure.audit.provider.LocalFileLogBuffer; +import com.xasecure.audit.provider.Log4jTracer; import com.xasecure.audit.provider.MiscUtil; public class HdfsAuditProvider extends BufferedAuditProvider { + private static final Log LOG = LogFactory.getLog(HdfsAuditProvider.class); public HdfsAuditProvider() { } @@ -28,7 +34,9 @@ public class HdfsAuditProvider extends BufferedAuditProvider { String localFileBufferArchiveDirectory = properties.get("local.archive.directory"); int localFileBufferArchiveFileCount = MiscUtil.parseInteger(properties.get("local.archive.max.file.count"), 10); - HdfsLogDestination mHdfsDestination = new HdfsLogDestination(); + DebugTracer tracer = new Log4jTracer(LOG); + + HdfsLogDestination mHdfsDestination = new HdfsLogDestination(tracer); mHdfsDestination.setDirectory(hdfsDestinationDirectory); mHdfsDestination.setFile(hdfsDestinationFile); @@ -37,7 +45,7 @@ public class HdfsAuditProvider extends BufferedAuditProvider { mHdfsDestination.setRolloverIntervalSeconds(hdfsDestinationRolloverIntervalSeconds); mHdfsDestination.setOpenRetryIntervalSeconds(hdfsDestinationOpenRetryIntervalSeconds); - LocalFileLogBuffer mLocalFileBuffer = new LocalFileLogBuffer(); + LocalFileLogBuffer mLocalFileBuffer = new LocalFileLogBuffer(tracer); mLocalFileBuffer.setDirectory(localFileBufferDirectory); mLocalFileBuffer.setFile(localFileBufferFile); @@ -50,3 +58,6 @@ public class HdfsAuditProvider extends BufferedAuditProvider { setBufferAndDestination(mLocalFileBuffer, mHdfsDestination); } } + + + http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/185ab086/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsLogDestination.java ---------------------------------------------------------------------- diff --git a/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsLogDestination.java b/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsLogDestination.java index 60fda6c..2939a5c 100644 --- a/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsLogDestination.java +++ b/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsLogDestination.java @@ -19,20 +19,18 @@ package com.xasecure.audit.provider.hdfs; -import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.net.URI; -import java.util.Date; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.log4j.helpers.LogLog; +import com.xasecure.audit.provider.DebugTracer; import com.xasecure.audit.provider.LogDestination; import com.xasecure.audit.provider.MiscUtil; @@ -44,6 +42,7 @@ public class HdfsLogDestination implements LogDestination { private boolean mIsAppend = true; private int mRolloverIntervalSeconds = 24 * 60 * 60; private int mOpenRetryIntervalSeconds = 60; + private DebugTracer mLogger = null; private OutputStreamWriter mWriter = null; private String mHdfsFilename = null; @@ -52,7 +51,8 @@ public class HdfsLogDestination implements LogDestination { private long mLastOpenFailedTime = 0; private boolean mIsStopInProgress = false; - public HdfsLogDestination() { + public HdfsLogDestination(DebugTracer tracer) { + mLogger = tracer; } public String getDirectory() { @@ -105,16 +105,16 @@ public class HdfsLogDestination implements LogDestination { @Override public void start() { - LogLog.debug("==> HdfsLogDestination.start()"); + mLogger.debug("==> HdfsLogDestination.start()"); openFile(); - LogLog.debug("<== HdfsLogDestination.start()"); + mLogger.debug("<== HdfsLogDestination.start()"); } @Override public void stop() { - LogLog.debug("==> HdfsLogDestination.stop()"); + mLogger.debug("==> HdfsLogDestination.stop()"); mIsStopInProgress = true; @@ -122,7 +122,7 @@ public class HdfsLogDestination implements LogDestination { mIsStopInProgress = false; - LogLog.debug("<== HdfsLogDestination.stop()"); + mLogger.debug("<== HdfsLogDestination.stop()"); } @Override @@ -157,7 +157,7 @@ public class HdfsLogDestination implements LogDestination { ret = true; } catch (IOException excp) { - LogLog.warn("HdfsLogDestination.sendStringified(): write failed", excp); + mLogger.warn("HdfsLogDestination.sendStringified(): write failed", excp); closeFile(); } @@ -167,7 +167,7 @@ public class HdfsLogDestination implements LogDestination { } private void openFile() { - LogLog.debug("==> HdfsLogDestination.openFile()"); + mLogger.debug("==> HdfsLogDestination.openFile()"); closeFile(); @@ -183,7 +183,7 @@ public class HdfsLogDestination implements LogDestination { Configuration conf = null; try { - LogLog.debug("HdfsLogDestination.openFile(): opening file " + mHdfsFilename); + mLogger.debug("HdfsLogDestination.openFile(): opening file " + mHdfsFilename); URI uri = URI.create(mHdfsFilename); @@ -217,14 +217,16 @@ public class HdfsLogDestination implements LogDestination { try { if(parentPath != null&& fileSystem != null && !fileSystem.exists(parentPath) && fileSystem.mkdirs(parentPath)) { ostream = fileSystem.create(pathLogfile); + } else { + logException("HdfsLogDestination.openFile() failed", ex); } } catch (IOException e) { - LogLog.warn("HdfsLogDestination.openFile() failed", e); + logException("HdfsLogDestination.openFile() failed", e); } catch (Throwable e) { - LogLog.warn("HdfsLogDestination.openFile() failed", e); + mLogger.warn("HdfsLogDestination.openFile() failed", e); } } catch(Throwable ex) { - LogLog.warn("HdfsLogDestination.openFile() failed", ex); + mLogger.warn("HdfsLogDestination.openFile() failed", ex); } finally { // TODO: unset the property set above to exclude auditing of logfile opening // System.setProperty(hdfsCurrentFilenameProperty, null); @@ -233,22 +235,22 @@ public class HdfsLogDestination implements LogDestination { mWriter = createWriter(ostream); if(mWriter != null) { - LogLog.debug("HdfsLogDestination.openFile(): opened file " + mHdfsFilename); + mLogger.debug("HdfsLogDestination.openFile(): opened file " + mHdfsFilename); mNextFlushTime = System.currentTimeMillis() + (mFlushIntervalSeconds * 1000L); mLastOpenFailedTime = 0; } else { - LogLog.warn("HdfsLogDestination.openFile(): failed to open file for write " + mHdfsFilename); + mLogger.warn("HdfsLogDestination.openFile(): failed to open file for write " + mHdfsFilename); mHdfsFilename = null; mLastOpenFailedTime = System.currentTimeMillis(); } - LogLog.debug("<== HdfsLogDestination.openFile(" + mHdfsFilename + ")"); + mLogger.debug("<== HdfsLogDestination.openFile(" + mHdfsFilename + ")"); } private void closeFile() { - LogLog.debug("==> HdfsLogDestination.closeFile()"); + mLogger.debug("==> HdfsLogDestination.closeFile()"); OutputStreamWriter writer = mWriter; @@ -259,23 +261,21 @@ public class HdfsLogDestination implements LogDestination { writer.flush(); writer.close(); } catch(IOException excp) { - if(! mIsStopInProgress) { // during shutdown, the underlying FileSystem might already be closed; so don't print error details - LogLog.warn("HdfsLogDestination: failed to close file " + mHdfsFilename, excp); - } + logException("HdfsLogDestination: failed to close file " + mHdfsFilename, excp); } } - LogLog.debug("<== HdfsLogDestination.closeFile()"); + mLogger.debug("<== HdfsLogDestination.closeFile()"); } private void rollover() { - LogLog.debug("==> HdfsLogDestination.rollover()"); + mLogger.debug("==> HdfsLogDestination.rollover()"); closeFile(); openFile(); - LogLog.debug("<== HdfsLogDestination.rollover()"); + mLogger.debug("<== HdfsLogDestination.rollover()"); } private void checkFileStatus() { @@ -293,7 +293,7 @@ public class HdfsLogDestination implements LogDestination { mWriter.flush(); } catch (IOException excp) { - LogLog.warn("HdfsLogDestination: failed to flush", excp); + logException("HdfsLogDestination: failed to flush", excp); } } } @@ -306,7 +306,7 @@ public class HdfsLogDestination implements LogDestination { try { writer = new OutputStreamWriter(os, mEncoding); } catch(UnsupportedEncodingException excp) { - LogLog.warn("HdfsLogDestination.createWriter(): failed to create output writer.", excp); + mLogger.warn("HdfsLogDestination.createWriter(): failed to create output writer.", excp); } } @@ -339,6 +339,20 @@ public class HdfsLogDestination implements LogDestination { return ret; } + + private void logException(String msg, IOException excp) { + if(mIsStopInProgress) { // during shutdown, the underlying FileSystem might already be closed; so don't print error details + return; + } + + String excpMsgToExclude = "Filesystem closed"; + String excpMsg = excp != null ? excp.getMessage() : null; + boolean excpExcludeLogging = (excpMsg != null && excpMsg.contains(excpMsgToExclude)); + + if(! excpExcludeLogging) { + mLogger.warn(msg, excp); + } + } @Override public String toString() {