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:actions>
<map:action
- logger="your.specific.logging.category" name="log"
src="whatever.you.want.LogAction"
/>
- logger="your.specific.logging.category" name="log"
</map:actions>
</map:components> }}}
Sitemap usage
{{{<map:match pattern="something/*">
<map:act type="log">
<map:parameter name="msg" value="request to something/{1}"/>
</map:act>
- . .
}}}