make the logCloseLoop() methods members of the Log class

so they can be used everywhere
This commit is contained in:
zab2
2013-09-08 12:55:05 +00:00
parent 78a426e9ac
commit 592680302f
5 changed files with 33 additions and 46 deletions

View File

@ -36,7 +36,7 @@ class I2PSocketFull implements I2PSocket {
public void close() throws IOException {
if (!_closed.compareAndSet(false,true)) {
// log a trace to find out why
LogUtil.logCloseLoop(log, "I2PSocket",_localPeer,"-->",_remotePeer,_connection);
log.logCloseLoop("I2PSocket",_localPeer,"-->",_remotePeer,_connection);
return;
}
Connection c = _connection;

View File

@ -316,7 +316,7 @@ public class I2PSocketManagerFull implements I2PSocketManager {
public void destroySocketManager() {
if (!_isDestroyed.compareAndSet(false,true)) {
// shouldn't happen, log a stack trace to find out why it happened
LogUtil.logCloseLoop(_log, "I2PSocketManager", getName());
_log.logCloseLoop("I2PSocketManager", getName());
return;
}
_connectionManager.setAllowIncomingConnections(false);

View File

@ -1,41 +0,0 @@
package net.i2p.client.streaming;
import net.i2p.util.Log;
/**
* Debug logging utility
* @since 0.9.7
*/
class LogUtil {
private LogUtil() {}
/**
* logs a loop when closing a resource with level INFO
* @param desc vararg description
* @param log logger for the class we're intersted in
*/
static void logCloseLoop(Log log, Object... desc) {
logCloseLoop(log, Log.INFO, desc);
}
/**
* Logs a close loop when closing a resource
* @param desc vararg description of the resource
* @param log logger to use
* @param level level at which to log
*/
static void logCloseLoop(Log log, int level, Object... desc) {
if (!log.shouldLog(level))
return;
// catenate all toString()s
String descString = "close() loop in";
for (Object o : desc) {
descString += " ";
descString += String.valueOf(o);
}
Exception e = new Exception("check stack trace");
log.log(level,descString,e);
}
}

View File

@ -372,7 +372,7 @@ class MessageOutputStream extends OutputStream {
public void close() throws IOException {
if (!_closed.compareAndSet(false,true)) {
synchronized (_dataLock) { _dataLock.notifyAll(); }
LogUtil.logCloseLoop(_log, "MOS");
_log.logCloseLoop("MOS");
return;
}
// setting _closed before flush() will force flush() to send a CLOSE packet
@ -410,7 +410,7 @@ class MessageOutputStream extends OutputStream {
*/
public void closeInternal() {
if (!_closed.compareAndSet(false,true)) {
LogUtil.logCloseLoop(_log, "close internal");
_log.logCloseLoop("close internal");
return;
}
_flusher.cancel();
@ -501,7 +501,7 @@ class MessageOutputStream extends OutputStream {
void destroy() {
if (!_closed.compareAndSet(false,true)) {
LogUtil.logCloseLoop(_log, "destroy()");
_log.logCloseLoop("destroy()");
return;
}
_flusher.cancel();

View File

@ -184,6 +184,34 @@ public class Log {
public boolean shouldLog(int priority) {
return priority >= _minPriority;
}
/**
* logs a loop when closing a resource with level INFO
* @param desc vararg description
*/
public void logCloseLoop(Object... desc) {
logCloseLoop(Log.INFO, desc);
}
/**
* Logs a close loop when closing a resource
* @param desc vararg description of the resource
* @param level level at which to log
*/
public void logCloseLoop(int level, Object... desc) {
if (!shouldLog(level))
return;
// catenate all toString()s
String descString = "close() loop in";
for (Object o : desc) {
descString += " ";
descString += String.valueOf(o);
}
Exception e = new Exception("check stack trace");
log(level,descString,e);
}
public String getName() {
if (_className != null) return _className;