Created
August 27, 2010 16:58
-
-
Save abyx/553724 to your computer and use it in GitHub Desktop.
Logback converters for username and sessions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SessionConverter extends ClassicConverter { | |
@Override | |
public String convert(ILoggingEvent event) { | |
RequestAttributes attrs = RequestContextHolder.getRequestAttributes(); | |
if (attrs != null) { | |
return attrs.getSessionId(); | |
} | |
return "NO_SESSION"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserConverter extends ClassicConverter { | |
@Override | |
public String convert(ILoggingEvent event) { | |
Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | |
if (auth != null) { | |
return auth.getName(); | |
} | |
return "NO_USER"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment