[
http://jira.magnolia-cms.com/browse/MAGNOLIA-2635?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21495#action_21495
]
Fabrizio Giustina commented on MAGNOLIA-2635:
---------------------------------------------
> ... but it seems slightly redundant with the audit features we've added with
> MAGNOLIA-764
well, not really. The reason for this is not to trace user activity, but just
to add additional information to error logging (for example: if you get an
error in a jcr query you can also see in the log which page contains the bad
query)
> Note that as I see it, it could also be a totally independent module, it
> doesn't seem like it has to be in core.
it's a so small thing that IMHO should be on by default, we could just think
about placing those two lines in ContextFilter and nothing more... a module for
this looks overkilling and it's a small feature anybody could love if on by
default in magnolia.
So, avoiding update tasks and so on, what about this simple addiction to the
existing filter? Something enough simple for committing it tonight? ;)
{noformat}
Index: ContextFilter.java
===================================================================
--- ContextFilter.java (revision 22787)
+++ ContextFilter.java (working copy)
@@ -46,6 +46,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
/**
@@ -70,6 +71,14 @@
if (!MgnlContext.hasInstance() || MgnlContext.isSystemInstance()) {
MgnlContext.initAsWebContext(request, response, servletContext);
contextSet = true;
+ 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);
+ }
}
if (!contextSet) {
// push req/res every time except the first time
@@ -87,6 +96,10 @@
MgnlContext.release();
MgnlContext.setInstance(null);
}
+
+ // cleanup
+ MDC.remove("requesturi");
+ MDC.remove("userid");
}
}
{noformat}
> 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]>
----------------------------------------------------------------