[logback-dev] svn commit: r1456 - in logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran: . action
noreply.seb at qos.ch
noreply.seb at qos.ch
Fri Mar 23 15:15:53 CET 2007
Author: seb
Date: Fri Mar 23 15:15:53 2007
New Revision: 1456
Added:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/ConsolePluginAction.java
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java
Log:
Added an action that creates a SocketAppender and attaches it to the root logger.
The action is bound to the pattern "consolePlugin" and requires a "port=xxx" attribute.
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java Fri Mar 23 15:15:53 2007
@@ -11,6 +11,7 @@
package ch.qos.logback.classic.joran;
import ch.qos.logback.classic.joran.action.ConfigurationAction;
+import ch.qos.logback.classic.joran.action.ConsolePluginAction;
import ch.qos.logback.classic.joran.action.EvaluatorAction;
import ch.qos.logback.classic.joran.action.JMXConfiguratorAction;
import ch.qos.logback.classic.joran.action.LayoutAction;
@@ -60,6 +61,8 @@
rs.addRule(new Pattern("configuration/jmxConfigurator"), new JMXConfiguratorAction());
rs.addRule(new Pattern("configuration/include"), new IncludeFileAction());
+
+ rs.addRule(new Pattern("configuration/consolePlugin"), new ConsolePluginAction());
}
}
Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/ConsolePluginAction.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/ConsolePluginAction.java Fri Mar 23 15:15:53 2007
@@ -0,0 +1,50 @@
+package ch.qos.logback.classic.joran.action;
+
+import org.xml.sax.Attributes;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.net.SocketAppender;
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.spi.ActionException;
+import ch.qos.logback.core.joran.spi.InterpretationContext;
+
+public class ConsolePluginAction extends Action {
+
+ private static final String PORT_ATTR = "port";
+
+ @Override
+ public void begin(InterpretationContext ec, String name, Attributes attributes)
+ throws ActionException {
+ String portStr = attributes.getValue(PORT_ATTR);
+
+ if (portStr == null) {
+ addError("The ConsolePlugin configuration requires a port attribute.");
+ }
+
+ Integer port = null;
+ try {
+ port = Integer.valueOf(portStr);
+ } catch (NumberFormatException ex) {
+ addError("Port " + portStr
+ + " in ConsolePlugin config is not a correct number");
+ }
+
+ LoggerContext lc = (LoggerContext)ec.getContext();
+ SocketAppender appender = new SocketAppender();
+ appender.setContext(lc);
+ appender.setIncludeCallerData(true);
+ appender.setRemoteHost("localhost");
+ appender.setPort(port.intValue());
+ appender.start();
+ Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
+ root.addAppender(appender);
+
+ addInfo("Sending LoggingEvents to the plugin using port " + port);
+ }
+
+ @Override
+ public void end(InterpretationContext ec, String name) throws ActionException {
+
+ }
+}
More information about the logback-dev
mailing list