Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
logback-classic/src/main/java/ch/qos/logback/classic/joran/action/SocketRemoteAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2011, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
package ch.qos.logback.classic.joran.action; | ||
|
||
import org.xml.sax.Attributes; | ||
|
||
import ch.qos.logback.classic.net.SocketRemote; | ||
import ch.qos.logback.core.joran.action.Action; | ||
import ch.qos.logback.core.joran.spi.ActionException; | ||
import ch.qos.logback.core.joran.spi.InterpretationContext; | ||
import ch.qos.logback.core.util.OptionHelper; | ||
|
||
/** | ||
* A Joran {@link Action} for a {@link SocketRemote} configuration. | ||
* | ||
* @author Carl Harris | ||
*/ | ||
public class SocketRemoteAction extends Action { | ||
|
||
private SocketRemote remote; | ||
private boolean inError; | ||
|
||
@Override | ||
public void begin(InterpretationContext ic, String name, | ||
Attributes attributes) throws ActionException { | ||
String className = attributes.getValue(CLASS_ATTRIBUTE); | ||
if (OptionHelper.isEmpty(className)) { | ||
className = SocketRemote.class.getCanonicalName(); | ||
} | ||
|
||
try { | ||
addInfo("About to instantiate remote of type [" + className + "]"); | ||
|
||
remote = (SocketRemote) OptionHelper.instantiateByClassName( | ||
className, SocketRemote.class, context); | ||
remote.setContext(context); | ||
|
||
String remoteName = ic.subst(attributes.getValue(NAME_ATTRIBUTE)); | ||
if (OptionHelper.isEmpty(remoteName)) { | ||
addWarn("No name given for remote of type " + className | ||
+ "]."); | ||
} else { | ||
remote.setName(remoteName); | ||
addInfo("Naming remote as [" + remoteName + "]"); | ||
} | ||
|
||
ic.pushObject(remote); | ||
} | ||
catch (Exception ex) { | ||
inError = true; | ||
addError("Could not create a remote of type [" + className + "].", ex); | ||
throw new ActionException(ex); | ||
} | ||
} | ||
|
||
@Override | ||
public void end(InterpretationContext ic, String name) | ||
throws ActionException { | ||
|
||
if (inError) return; | ||
|
||
remote.start(); | ||
|
||
Object o = ic.peekObject(); | ||
if (o != remote) { | ||
addWarn("The object at the of the stack is not the remote " + | ||
"pushed earlier."); | ||
} else { | ||
ic.popObject(); | ||
} | ||
} | ||
|
||
} |