Here's the code of an Action which logs a message to a specific logger.

This can be useful to keep track of visits to certain URLs in a logger that is distinct from the application logger.

Code

package whatever.you.want;

import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.acting.AbstractAction;
import org.apache.avalon.framework.parameters.Parameters;

import java.util.Map;

/** An Action which simply logs a message. */

public class LogAction extends AbstractAction {
    public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters)
    throws Exception {
        final String msg = parameters.getParameter("msg",null);
        if(msg!=null) {
            // of course, the log level could come from a Parameter as well
            if(getLogger().isInfoEnabled()) {
                getLogger().info(msg);
            }
        }

        // don't execute what's inside this action, it's just here to log something
        return null;
    }
}

Sitemap declaration

{{{<map:components>

</map:components> }}}

Sitemap usage

{{{<map:match pattern="something/*">

}}}

LogAction (last edited 2009-09-20 23:41:26 by localhost)