Trace current URL/userid for logging
------------------------------------
Key: MAGNOLIA-2635
URL: http://jira.magnolia-cms.com/browse/MAGNOLIA-2635
Project: Magnolia
Issue Type: Improvement
Components: core
Affects Versions: 4.0 RC3
Reporter: Fabrizio Giustina
Assignee: Fabrizio Giustina
Priority: Minor
This is something that I would like to see added by default, since we are in RC
phase I'll describe it here to decide if/when it should be added.
Using log4j (and also with slf4j) we can add useful informations to logs by
adding some variables to MDC by default (mapped diagnostic context, see
http://wiki.apache.org/logging-log4j/NDCvsMDC ).
Those additional info should be added by a filter. The code below shows what
the filter should do (I am not attaching a proper patch since this is only for
discussion). The filter should go exactly after the context filter (or we could
decide to put it *into* the context filter maybe.
{noformat}
public void doFilter(HttpServletRequest request, HttpServletResponse
response, FilterChain chain)
throws IOException, ServletException
{
try
{
MDC.put("requesturi", request.getRequestURI());
MDC.put("userid", MgnlContext.getUser().getName());
}
catch (Throwable e)
{
// whatever it happens, only log
log.debug(e.getMessage(), e);
}
try
{
chain.doFilter(request, response);
}
finally
{
// cleanup
MDC.remove("requesturi");
MDC.remove("userid");
}
}
{noformat}
Doing this, anywhere in the log4j.xml log patterns the following placeholders
can be used in order to print out the current uri and the logged in user:
{noformat}
%X{requesturi}
%X{userid}
{noformat}
This looks very useful also in the mail appender, if you enable it in running
sites.
This is an example of the content that can be added to error mails:
{noformat}
===================================
My Magnolia app
Version: 1.4.0
Server: c139343z
Url: /.magnolia/pages/test.html
User: joe
Number of occurrences: 2
===================================
[c020890-sun01] ERROR 23.02.2009 01:07:08
info.magnolia.module.exchangesimple.SimpleSyndicator
SimpleSyndicator.java(run:77) -- Failed to activate content.
info.magnolia.cms.exchange.ExchangeException: Message received from subscriber:
Activation failed | /NZ/large
at
info.magnolia.module.exchangesimple.SimpleSyndicator.activate(SimpleSyndicator.java:175)
at
info.magnolia.module.exchangesimple.SimpleSyndicator$1.run(SimpleSyndicator.java:75)
....
.... (the usual stacktrace)
===================================
{noformat}
Although this can be easily implemented I think that at least the filter that
pushes informations to log4j MDC should be added by default. What about adding
it for 4.0?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.magnolia-cms.com/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------