Package org.jpos.bsh
Class BSHLogListener
- java.lang.Object
-
- org.jpos.bsh.BSHLogListener
-
- All Implemented Interfaces:
java.util.EventListener
,Configurable
,LogListener
public class BSHLogListener extends java.lang.Object implements LogListener, Configurable
This is a log listener that reads its actions from Bean Shell scripts. You can define many scripts, and the order in wich they are called, also you can define scripts whose name depends on the event being processed, and the realm of the object that generated it. This way you can set a configuration like this:
<log-listener class="org.jpos.bsh.BSHLoglistener"> <property name="source" value="general.bsh"/> <property name="source" value="tag_$tag.bsh"/> <!--this is to handle specific tags--> <property name="source" value="realm_$realm.bsh"/> <!-- to handle specific realms--> <property name="source" value="tag_$tag_realm_$realm.bsh"/> <!-- to handle specific tags from specific realms--> </log-listener>
If a source with the given name is not found, or it canbe read, it is not processed, so this lets you change what is processed in real time, if you put a file called tag_SystemMonitor_realm_monitor.bsh it will be executed whenever the system monitor is run.
If you want to filter an event so that the remaining log listeners don't see it, you have to set event = null in your script.
Other Configuration Options: Name Type Description filter-by-default boolean If true, filter the events if no script is processed, this way you can put a Log Listener that filters every thing unless you put some script file, even if it is empty, you also can dynamically change what kind of message are filtered by placing empty files with names like tag_SystemMonitor_realm_monitor.bsh in the previous example, if you "touch" a file with this name these events will begin to be processed. preload-scripts boolean If true scripts a loaded once, and kept in memory, being realoaded only if they are touched. This is good when you have lots of RAM memory but ou have troubles with speed save-name-space boolean If true the namespace of the script instance will be saved so that in the next event you can access them from the script, by default it's off, this property is overriden if the script exposes a boolean variable named saveNameSpace reload long this property is used if the preload-script property is true, is the time in milliseconds between updates in the script, during this time BSHLogListener will not check if the script source was modified or deleted on disk
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
BSHLogListener.ScriptInfo
-
Field Summary
Fields Modifier and Type Field Description protected Configuration
cfg
Holds the configuration for this objectprotected static java.lang.String[]
patterns
protected java.util.Map<java.lang.String,BSHLogListener.ScriptInfo>
scripts
-
Constructor Summary
Constructors Constructor Description BSHLogListener()
Creates a new instance of BSHLogListener
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addScriptInfo(java.lang.String filename, java.lang.String code, long lastModified)
protected BSHLogListener.ScriptInfo
getScriptInfo(java.lang.String filename)
protected java.lang.String
loadCode(java.io.File f)
LogEvent
log(LogEvent ev)
protected static java.lang.String[]
replace(java.lang.String[] src, java.lang.String[] patterns, java.lang.String[] to)
void
setConfiguration(Configuration cfg)
-
-
-
Field Detail
-
cfg
protected Configuration cfg
Holds the configuration for this object
-
patterns
protected static final java.lang.String[] patterns
-
scripts
protected java.util.Map<java.lang.String,BSHLogListener.ScriptInfo> scripts
-
-
Constructor Detail
-
BSHLogListener
public BSHLogListener()
Creates a new instance of BSHLogListener
-
-
Method Detail
-
setConfiguration
public void setConfiguration(Configuration cfg)
- Specified by:
setConfiguration
in interfaceConfigurable
- Parameters:
cfg
- Configuration object
-
replace
protected static java.lang.String[] replace(java.lang.String[] src, java.lang.String[] patterns, java.lang.String[] to)
-
log
public LogEvent log(LogEvent ev)
- Specified by:
log
in interfaceLogListener
-
loadCode
protected java.lang.String loadCode(java.io.File f) throws java.io.IOException
- Throws:
java.io.IOException
-
getScriptInfo
protected BSHLogListener.ScriptInfo getScriptInfo(java.lang.String filename)
-
addScriptInfo
protected void addScriptInfo(java.lang.String filename, java.lang.String code, long lastModified)
-
-