Java SimpleRuleStore-class And Method Code Example

Here is an example of how to use the SimpleRuleStore class from the Logback library:

import ch.qos.logback.core.joran.conditional.ThenAction;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.spi.LifeCycle;
import ch.qos.logback.core.spi.RuleStore;

public class SimpleRuleStore extends ContextAwareBase implements RuleStore, LifeCycle {
    Map<String, ThenAction> ruleMap = new HashMap<String, ThenAction>();

    public void addRule(String pattern, ThenAction action) {
        ruleMap.put(pattern, action);

    public ThenAction getAction(String key) {
        return ruleMap.get(key);

    public void start() {
        // start any resources required by the RuleStore

    public void stop() {
        // stop any resources used by the RuleStore

    public boolean isStarted() {
        // return true if the RuleStore is started, false otherwise

This class would be used in a way where it would evaluate a pattern and return the corresponding ThenAction.

It also implement LifeCycle interface which can be used to start/stop and check if the rule store is running or not.

Please keep in mind that Logback is just one of many logging libraries available in Java, and that the specifics of how to use it may depend on the version you are using and your specific use case.