[ 
https://issues.apache.org/jira/browse/LOG4J2-1588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15535783#comment-15535783
 ] 

Rainer Schnitker edited comment on LOG4J2-1588 at 9/30/16 11:51 AM:
--------------------------------------------------------------------

This issure affects version 2.6.2.
Perhaps there are other alternatives to set a request context for an logging 
event. 

To identify the same client request in the log, we assign the thread name to 
the current client hostname or ip address plus the thead id.
The log uses the logging pattern:  {code} %d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p 
%c - %m%n {code}

This works with all logging frameworks, that supports the thread name.


was (Author: rainer schnitker):
This issure affects version 2.6.2.
Perhaps there are other alternatives to set a request context for an logging 
event. 

To identify the same client request in the log, we assign the thread name to 
the current client hostname or ip address plus the thead id.
The log uses the logging pattern:  %d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %c - 
%m%n

This works with all logging frameworks, that supports the thread name.

> Console or File Logger caches thread name, but not in older log4j2 versions
> ---------------------------------------------------------------------------
>
>                 Key: LOG4J2-1588
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1588
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.6.2
>         Environment: Windows, Grizzly HTTP container, SLF4J API, Log4j2
>            Reporter: Rainer Schnitker
>
> Log4j2 2.6.x seems to cache the thread name. A revert to version 2.4.1. 
> works! This affects synchronous logger: console, RollingFile
> My sample code (JAX-RS Filter):
> {code}
> import java.io.IOException;
> import javax.annotation.Priority;
> import javax.inject.Inject;
> import javax.ws.rs.container.ContainerRequestContext;
> import javax.ws.rs.container.ContainerRequestFilter;
> import javax.ws.rs.ext.Provider;
> import org.glassfish.grizzly.http.server.Request;
> import org.slf4j.LoggerFactory;
> @Provider
> @Priority(Integer.MIN_VALUE)
> public class GrizzlyRequestFilter implements ContainerRequestFilter {
>     @Inject
>     javax.inject.Provider< Request > provider;
>     @Override
>     public void filter( ContainerRequestContext requestContext ) throws 
> IOException {
>         Request request = this.provider.get();
>         Thread thread = Thread.currentThread();
>         thread.setName( request.getRemoteHost() + '/' + thread.getId() );
>         
>         // oops: logger thread name != expected
>         LoggerFactory.getLogger(GrizzlyRequestFilter.class)
>             .info( "expected thread name:" + request.getRemoteHost() + '/' + 
> thread.getId() );
>         
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to