Index: logback-classic/src/main/java/ch/qos/logback/classic/joran/action/ConsolePluginAction.java =================================================================== --- logback-classic/src/main/java/ch/qos/logback/classic/joran/action/ConsolePluginAction.java (revision 1959) +++ logback-classic/src/main/java/ch/qos/logback/classic/joran/action/ConsolePluginAction.java (working copy) @@ -12,13 +12,16 @@ public class ConsolePluginAction extends Action { private static final String PORT_ATTR = "port"; + private static final String SILENT_ATTR = "silent"; private static final Integer DEFAULT_PORT = 4321; @Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { String portStr = attributes.getValue(PORT_ATTR); + String silentStr = attributes.getValue(SILENT_ATTR); Integer port = null; + boolean silentMode = false; if (portStr == null) { port = DEFAULT_PORT; @@ -30,9 +33,18 @@ + " in ConsolePlugin config is not a correct number"); } } + + if ( + (silentStr == null) || silentStr.equals("") + || silentStr.equals("false") || silentStr.equals("null")) { + addInfo(SILENT_ATTR + " attribute not set"); + } else { + silentMode = true; + } LoggerContext lc = (LoggerContext)ec.getContext(); SocketAppender appender = new SocketAppender(); + appender.setSilentMode(silentMode); appender.setContext(lc); appender.setIncludeCallerData(true); appender.setRemoteHost("localhost"); Index: logback-core/src/main/java/ch/qos/logback/core/net/SocketAppenderBase.java =================================================================== --- logback-core/src/main/java/ch/qos/logback/core/net/SocketAppenderBase.java (revision 1959) +++ logback-core/src/main/java/ch/qos/logback/core/net/SocketAppenderBase.java (working copy) @@ -53,6 +53,8 @@ protected int counter = 0; + private boolean silentMode = false; + // reset the ObjectOutputStream every 70 calls private static final int RESET_FREQUENCY = 70; @@ -140,7 +142,9 @@ msg += " We will try again later."; fireConnector(); // fire the connector thread } - addError(msg, e); + if (!silentMode) { + addError(msg, e); + } } } @@ -258,8 +262,12 @@ public int getReconnectionDelay() { return reconnectionDelay; } + /** Option to be silent when using <consolePlugin/> **/ + public void setSilentMode(boolean silentMode) { + this.silentMode = silentMode; + } - /** +/** * The Connector will reconnect when the server becomes available again. It * does this by attempting to open a new connection every * reconnectionDelay milliseconds. Index: logback-site/src/site/pages/consolePlugin.html =================================================================== --- logback-site/src/site/pages/consolePlugin.html (revision 1959) +++ logback-site/src/site/pages/consolePlugin.html (working copy) @@ -113,6 +113,26 @@ of this document.

+

+ If no server is listening on the configured port, an ERROR will be printed to system out. Optionally + you can specify that the consolePlugin should be silent with the silent attribute. + This is typically useful when running i.e. on a buildserver and you don't want the buildlog polluted + with messages like: +

+
12:12:57,706 |-ERROR in ch.qos.logback.classic.net.SocketAppender[null] - Could not connect to remote logback server at [localhost]. We will try again later. java.net.ConnectException: Connection refused: connect
+        at java.net.ConnectException: Connection refused: connect
+        at      at java.net.PlainSocketImpl.socketConnect(Native Method)
+        ....(stacktrace abbreviated)
+ + +
<?xml version="1.0" encoding="UTF-8"?>
+
+<configuration>
+
+  <consolePlugin silent="true" />
+  
+</configuration>
+

Using the logback plugin