garydgregory commented on a change in pull request #287: adding support for 
session attributes in log4j-web
URL: https://github.com/apache/logging-log4j2/pull/287#discussion_r298254564
 
 

 ##########
 File path: log4j-web/src/main/java/org/apache/logging/log4j/web/WebLookup.java
 ##########
 @@ -91,6 +92,19 @@ public String lookup(final LogEvent event, final String 
key) {
                     HttpServletRequest.class.cast(req).getParameter(name) : 
null;
         }
 
+        if (key.startsWith(SESSION_ATTR_PREFIX)) {
+            final ServletRequest req = getRequest();
+            if (HttpServletRequest.class.isInstance(req)) {
+                final HttpSession session = 
HttpServletRequest.class.cast(req).getSession(false);
+                if (session != null) {
+                    final String name = 
key.substring(SESSION_ATTR_PREFIX.length());
+                    final Object attribute = session.getAttribute(name);
+                    return attribute == null ? null : 
String.valueOf(attribute);
 
 Review comment:
   Hide the ternary: `return Objects.toString(session.getAttribute(name), 
null);`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to