[ 
https://issues.apache.org/jira/browse/LOG4J2-1608?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gary Gregory updated LOG4J2-1608:
---------------------------------
    Description: 
The method 
{{org.apache.logging.log4j.web.appender.ServletAppender.append(LogEvent)}} is 
defined as:

{code:java}
    @Override
    public void append(final LogEvent event) {
        servletContext.log(((AbstractStringLayout) 
getLayout()).toSerializable(event));
    }
{code}

Instead of:

{code:java}
    @Override
    public void append(final LogEvent event) {
        servletContext.log(((AbstractStringLayout) 
getLayout()).toSerializable(event), event.getThrown());
    }
{code}

We should use {{javax.servlet.ServletContext.log(String, Throwable)}} instead 
of {{javax.servlet.ServletContext.log(String)}}.

We do not give the best information we have to the servlet context logging.

The tricky part is that to avoid logging the exception twice like in our test 
{{org.apache.logging.log4j.web.ServletAppenderTest}}. To avoid the double 
logging, we could (1) document not using a %exception in the pattern layout.

That or (yikes) (2) provide a variation of the toSerializable(event) like 
toSerializable(event, false), where the boolean is an ignoreException 
parameter. It seems there are plenty of places where exceptions are treated 
specially already, this would be another.

I like (1) better because it is simpler.

In addition the test and documentation should mention the use of {{%ex\{none}}} 
to avoid appending exceptions to messages when using the ServletAppender.


  was:
The method 
{{org.apache.logging.log4j.web.appender.ServletAppender.append(LogEvent)}} is 
defined as:

{code:java}
    @Override
    public void append(final LogEvent event) {
        servletContext.log(((AbstractStringLayout) 
getLayout()).toSerializable(event));
    }
{code}

Instead of:

{code:java}
    @Override
    public void append(final LogEvent event) {
        servletContext.log(((AbstractStringLayout) 
getLayout()).toSerializable(event), event.getThrown());
    }
{code}

We should use {{javax.servlet.ServletContext.log(String, Throwable)}} instead 
of {{javax.servlet.ServletContext.log(String)}}.

We do not give the best information we have to the servlet context logging.

The tricky part is that to avoid logging the exception twice like in our test 
{{org.apache.logging.log4j.web.ServletAppenderTest}}. To avoid the double 
logging, we could (1) document not using a %exception in the pattern layout.

That or (yikes) (2) provide a variation of the toSerializable(event) like 
toSerializable(event, false), where the boolean is an ignoreException 
parameter. It seems there are plenty of places where exceptions are treated 
specially already, this would be another.

I like (1) better because it is simpler.

In addition the test and documentation should mention the use of {{%noex}} to 
avoid appending exceptions to messages when using the ServletAppender.



> ServletAppender does not provide throwable object to ServletContext
> -------------------------------------------------------------------
>
>                 Key: LOG4J2-1608
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1608
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.6.2
>            Reporter: Gary Gregory
>
> The method 
> {{org.apache.logging.log4j.web.appender.ServletAppender.append(LogEvent)}} is 
> defined as:
> {code:java}
>     @Override
>     public void append(final LogEvent event) {
>         servletContext.log(((AbstractStringLayout) 
> getLayout()).toSerializable(event));
>     }
> {code}
> Instead of:
> {code:java}
>     @Override
>     public void append(final LogEvent event) {
>         servletContext.log(((AbstractStringLayout) 
> getLayout()).toSerializable(event), event.getThrown());
>     }
> {code}
> We should use {{javax.servlet.ServletContext.log(String, Throwable)}} instead 
> of {{javax.servlet.ServletContext.log(String)}}.
> We do not give the best information we have to the servlet context logging.
> The tricky part is that to avoid logging the exception twice like in our test 
> {{org.apache.logging.log4j.web.ServletAppenderTest}}. To avoid the double 
> logging, we could (1) document not using a %exception in the pattern layout.
> That or (yikes) (2) provide a variation of the toSerializable(event) like 
> toSerializable(event, false), where the boolean is an ignoreException 
> parameter. It seems there are plenty of places where exceptions are treated 
> specially already, this would be another.
> I like (1) better because it is simpler.
> In addition the test and documentation should mention the use of 
> {{%ex\{none}}} to avoid appending exceptions to messages when using the 
> ServletAppender.



--
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