ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
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.
Date Sun, 05 Oct 2014 04:44:24 GMT
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 <mneethiraj@hortonworks.com>
Authored: Sat Oct 4 12:16:48 2014 -0700
Committer: mneethiraj <mneethiraj@hortonworks.com>
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<T> implements LogBuffer<T> {
@@ -49,6 +48,7 @@ public class LocalFileLogBuffer<T> implements LogBuffer<T> {
 	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<T> implements LogBuffer<T> {
 
 	private DestinationDispatcherThread<T> mDispatcherThread = null;
 	
-	public LocalFileLogBuffer() {
+	public LocalFileLogBuffer(DebugTracer tracer) {
+		mLogger = tracer;
 	}
 
 	public String getDirectory() {
@@ -127,18 +128,18 @@ public class LocalFileLogBuffer<T> implements LogBuffer<T>
{
 
 	@Override
 	public void start(LogDestination<T> destination) {
-		LogLog.debug("==> LocalFileLogBuffer.start()");
+		mLogger.debug("==> LocalFileLogBuffer.start()");
 
-		mDispatcherThread = new DestinationDispatcherThread<T>(this, destination);
+		mDispatcherThread = new DestinationDispatcherThread<T>(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<T> dispatcherThread = mDispatcherThread;
 		mDispatcherThread = null;
@@ -149,13 +150,13 @@ public class LocalFileLogBuffer<T> implements LogBuffer<T>
{
 			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<T> implements LogBuffer<T>
{
 
 				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<T> implements LogBuffer<T>
{
 	}
 
 	private synchronized void openFile() {
-		LogLog.debug("==> LocalFileLogBuffer.openFile()");
+		mLogger.debug("==> LocalFileLogBuffer.openFile()");
 
 		closeFile();
 
@@ -224,20 +225,20 @@ public class LocalFileLogBuffer<T> implements LogBuffer<T>
{
 		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<T> implements LogBuffer<T>
{
 				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<T> implements LogBuffer<T>
{
 			}
 		}
 
-		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<T> implements LogBuffer<T>
{
 
 				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<T> implements LogBuffer<T>
{
 				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<T> extends Thread {
 	private boolean                mStopThread        = false;
 	private LocalFileLogBuffer<T>  mFileLogBuffer     = null;
 	private LogDestination<T>      mDestination       = null;
+	private DebugTracer            mLogger            = null;
 
 	private String         mCurrentLogfile = null;
 	private BufferedReader mReader         = null;
 
-	public DestinationDispatcherThread(LocalFileLogBuffer<T> fileLogBuffer, LogDestination<T>
destination) {
+	public DestinationDispatcherThread(LocalFileLogBuffer<T> fileLogBuffer, LogDestination<T>
destination, DebugTracer tracer) {
 		super(DestinationDispatcherThread.class.getSimpleName() + "-" + System.currentTimeMillis());
 
+		mLogger = tracer;
+
 		mFileLogBuffer = fileLogBuffer;
 		mDestination   = destination;
 
@@ -347,7 +351,7 @@ class DestinationDispatcherThread<T> 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<T> extends Thread {
 			}
 		}
 
-		LogLog.debug("<== DestinationDispatcherThread.addLogfile(" + filename + ")");
+		mLogger.debug("<== DestinationDispatcherThread.addLogfile(" + filename + ")");
 	}
 
 	public void stopThread() {
@@ -376,11 +380,11 @@ class DestinationDispatcherThread<T> 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<T> 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<T> 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<T> 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<T> extends Thread {
 			archiveCurrentFile();
 		}
 
-		LogLog.debug("<== DestinationDispatcherThread.sendCurrentFile()");
+		mLogger.debug("<== DestinationDispatcherThread.sendCurrentFile()");
 
 		return ret;
 	}
@@ -518,7 +522,7 @@ class DestinationDispatcherThread<T> 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<T> extends Thread {
 	}
 
 	private void openCurrentFile() {
-		LogLog.debug("==> openCurrentFile(" + mCurrentLogfile + ")");
+		mLogger.debug("==> openCurrentFile(" + mCurrentLogfile + ")");
 
 		if(mCurrentLogfile != null) {
 			try {
@@ -538,15 +542,15 @@ class DestinationDispatcherThread<T> 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<T> extends Thread {
 		}
 		mReader = null;
 
-		LogLog.debug("<== closeCurrentFile(" + mCurrentLogfile + ")");
+		mLogger.debug("<== closeCurrentFile(" + mCurrentLogfile + ")");
 	}
 
 	private void archiveCurrentFile() {
@@ -574,7 +578,7 @@ class DestinationDispatcherThread<T> 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<T> 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<T> 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<T> 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<AuditEventBase> mHdfsDestination = new HdfsLogDestination<AuditEventBase>();
+		DebugTracer tracer = new Log4jTracer(LOG);
+
+		HdfsLogDestination<AuditEventBase> mHdfsDestination = new HdfsLogDestination<AuditEventBase>(tracer);
 
 		mHdfsDestination.setDirectory(hdfsDestinationDirectory);
 		mHdfsDestination.setFile(hdfsDestinationFile);
@@ -37,7 +45,7 @@ public class HdfsAuditProvider extends BufferedAuditProvider {
 		mHdfsDestination.setRolloverIntervalSeconds(hdfsDestinationRolloverIntervalSeconds);
 		mHdfsDestination.setOpenRetryIntervalSeconds(hdfsDestinationOpenRetryIntervalSeconds);
 
-		LocalFileLogBuffer<AuditEventBase> mLocalFileBuffer = new LocalFileLogBuffer<AuditEventBase>();
+		LocalFileLogBuffer<AuditEventBase> mLocalFileBuffer = new LocalFileLogBuffer<AuditEventBase>(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<T> implements LogDestination<T>
{
 	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<T> implements LogDestination<T>
{
 	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<T> implements LogDestination<T>
{
 
 	@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<T> implements LogDestination<T>
{
 
 		mIsStopInProgress = false;
 
-		LogLog.debug("<== HdfsLogDestination.stop()");
+		mLogger.debug("<== HdfsLogDestination.stop()");
 	}
 
 	@Override
@@ -157,7 +157,7 @@ public class HdfsLogDestination<T> implements LogDestination<T>
{
 
 				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<T> implements LogDestination<T>
{
 	}
 
 	private void openFile() {
-		LogLog.debug("==> HdfsLogDestination.openFile()");
+		mLogger.debug("==> HdfsLogDestination.openFile()");
 
 		closeFile();
 
@@ -183,7 +183,7 @@ public class HdfsLogDestination<T> implements LogDestination<T>
{
 		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<T> implements LogDestination<T>
{
 			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<T> implements LogDestination<T>
{
 		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<T> implements LogDestination<T>
{
 				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<T> implements LogDestination<T>
{
 
 				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<T> implements LogDestination<T>
{
 				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<T> implements LogDestination<T>
{
 
 		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() {


Mime
View raw message