Skip to content

Commit

Permalink
logging in ConcurrentServerRunner now uses methods of ContextAware
Browse files Browse the repository at this point in the history
ConcurrentServerRunner was delegating logging to methods defined by a
subclass.  For subclasses defined in core, these methods were simply
delegating to methods of ContextAware.  For subclasses defined elsewhere
(in which a LoggerContext might be available) logging might be handled
differently.

The logging produced by ConcurrentServerRunner is mostly intended to be
diagnostic, so for consistency (no matter which module might contain the
subclass) logging is now handled exclusively through ContextAware.  This
implies that this diagnostic logging is available only when the
LoggerContext is configured for debugging, but at least that limitation
is now consistent across subclasses of ConcurrentServerRunner.
  • Loading branch information
ceharris committed Apr 4, 2013
1 parent f55b54c commit 53ed3c4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 61 deletions.
Expand Up @@ -19,7 +19,6 @@
import org.slf4j.ILoggerFactory;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.net.server.ConcurrentServerRunner;
import ch.qos.logback.core.net.server.ServerListener;
Expand All @@ -35,7 +34,6 @@ class RemoteAppenderServerRunner
extends ConcurrentServerRunner<RemoteAppenderClient> {

private LoggerContext lc;
private Logger logger;

/**
* Constructs a new server runner.
Expand All @@ -53,43 +51,13 @@ public RemoteAppenderServerRunner(
protected boolean configureClient(RemoteAppenderClient client) {
LoggerContext lc = getLoggerContext();
if (lc == null) {
logError("logger context not yet available");
addError("logger context not yet available");
return false;
}

client.setLoggerContext(lc);
return true;
}

protected void logInfo(String message) {
Logger logger = getLogger();
if (logger != null) {
logger.info(message);
}
else {
addInfo(message);
}
}

protected void logError(String message) {
Logger logger = getLogger();
if (logger != null) {
logger.error(message);
}
else {
addError(message);
}
}

protected Logger getLogger() {
if (logger == null) {
LoggerContext lc = getLoggerContext();
if (lc != null) {
logger = lc.getLogger(getClass().getPackage().getName());
}
}
return logger;
}

protected LoggerContext getLoggerContext() {
if (lc == null) {
Expand Down
Expand Up @@ -112,7 +112,7 @@ public void accept(ClientVisitor<T> visitor) {
visitor.visit(client);
}
catch (RuntimeException ex) {
logError(client + ": " + ex);
addError(client + ": " + ex);
}
}
}
Expand All @@ -133,19 +133,19 @@ private Collection<T> copyClients() {
*/
public void run() {
try {
logInfo("listening on " + listener);
addInfo("listening on " + listener);
while (!Thread.currentThread().isInterrupted()) {
T client = listener.acceptClient();
if (!configureClient(client)) {
logError(client + ": connection dropped");
addError(client + ": connection dropped");
client.close();
continue;
}
try {
executor.execute(new ClientWrapper(client));
}
catch (RejectedExecutionException ex) {
logError(client + ": connection dropped");
addError(client + ": connection dropped");
client.close();
}
}
Expand All @@ -154,22 +154,18 @@ public void run() {
assert true; // ok... we'll shut down
}
catch (SocketException ex) {
logInfo(ex.toString());
addInfo(ex.toString());
}
catch (Exception ex) {
logError(ex.toString());
addError(ex.toString());
}

logInfo("shutting down");
addInfo("shutting down");
listener.close();
}

protected abstract boolean configureClient(T client);

protected abstract void logInfo(String message);

protected abstract void logError(String message);


private void addClient(T client) {
clientsLock.lock();
try {
Expand Down
Expand Up @@ -55,20 +55,4 @@ protected boolean configureClient(RemoteLoggerClient client) {
return true;
}

/**
* {@inheritDoc}
*/
@Override
protected void logInfo(String message) {
addInfo(message);
}

/**
* {@inheritDoc}
*/
@Override
protected void logError(String message) {
addError(message);
}

}

0 comments on commit 53ed3c4

Please sign in to comment.