Grails log4j pattern customization

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Grails log4j pattern customization

honiewelle
Hi all,

I was wondering if someone here know or is it even possible to add more information in log4j logs such as the current logged in user (using Spring security). Any help will be greatly appreciated.

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Grails log4j pattern customization

cazacugmihai
Hi,

Read this post: http://burtbeckwith.com/blog/?p=521

Cheers!
Mihai

On Mon, Dec 12, 2011 at 9:23 AM, honiewelle <[hidden email]> wrote:

> Hi all,
>
> I was wondering if someone here know or is it even possible to add more
> information in log4j logs such as the current logged in user (using Spring
> security). Any help will be greatly appreciated.
>
> Thanks!
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Grails-log4j-pattern-customization-tp4185021p4185021.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>



--
Mihai Cazacu
Software Engineer
E-mail: [hidden email]
Mobile: +40 745 254 657
Skype: cazacugmihai
Twitter: cazacugmihai

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Grails log4j pattern customization

honiewelle
Hi,

I followed the steps at burt's blog, however, I only keep on getting null in getUserPrincipal(). Has anyone tried using this method with 1.3.7?
Reply | Threaded
Open this post in threaded view
|

Re: Grails log4j pattern customization

Ian Roberts
On 13/12/2011 14:16, honiewelle wrote:
> Hi,
>
> I followed the steps at burt's blog, however, I only keep on getting null in
> getUserPrincipal(). Has anyone tried using this method with 1.3.7?

Are you using the Grails filter or the Servlet Filter approach?  If the
latter maybe the filters are ending up in the wrong order - your MDC
filter would need to come after the Spring Security filter in the chain
in order to be able to pick up the user.

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Grails log4j pattern customization

honiewelle
Yes,  i am using the servlet filter approach. I already placed the filter-mapping as the last entry in the templates/war/web.xml but I noticed that the arrangement is being changed when the application is being compiled into a war file (WEB-INF/web.xml) since grails is automatically inserting needed filters. Is there any additional configuration I am missing?



Ian Roberts wrote
On 13/12/2011 14:16, honiewelle wrote:
> Hi,
>
> I followed the steps at burt's blog, however, I only keep on getting null in
> getUserPrincipal(). Has anyone tried using this method with 1.3.7?

Are you using the Grails filter or the Servlet Filter approach?  If the
latter maybe the filters are ending up in the wrong order - your MDC
filter would need to come after the Spring Security filter in the chain
in order to be able to pick up the user.

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|

Re: Grails log4j pattern customization

Ian Roberts
On 14/12/2011 00:58, honiewelle wrote:
> Yes,  i am using the servlet filter approach. I already placed the
> filter-mapping as the last entry in the templates/war/web.xml but I noticed
> that the arrangement is being changed when the application is being compiled
> into a war file (WEB-INF/web.xml) since grails is automatically inserting
> needed filters. Is there any additional configuration I am missing?

Hmm, I'm not sure there's anything you can do about that then, other
than to write your own Grails plugin configured to load after the
spring-security-core one with a doWithWebDescriptor to put your filter
after the one added by s2.

Or maybe you could try this: since MDC entries can be any Object rather
than having to be Strings specifically, write your servlet filter in
Groovy rather than Java (in src/groovy) and use a GString:

MDC.put("username",
   "${SecurityContextHolder.context?.authentication?.name ?: 'N/A'}")

I haven't tried this but I believe the GString expression will be
evaluated only at the point where it is output by the logging appender,
rather than at the point where the filter is called, which means it
doesn't matter if your filter is ahead of the s2 one.

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email