You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@cocoon.apache.org by Apache Wiki <wi...@apache.org> on 2005/10/19 09:04:12 UTC
[Cocoon Wiki] Update of "LogAction" by BertrandDelacretaz
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Cocoon Wiki" for change notification.
The following page has been changed by BertrandDelacretaz:
http://wiki.apache.org/cocoon/LogAction
New page:
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 separate logger than 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) {
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"
/>
</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>
. . .
}}}