1

I am trying to print http status code in the log statement using spring boot log. But I do not know the pattern to print that. I used statusCode, status etc but doesnt work. Pls advise is there a way I can have status also printed in the logs for exception. Implementation is

log.error(e.getMessage(), e);

Logback xml

<appender name="json.stdout" class="ch.qos.logback.core.ConsoleAppender">
            <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
                <providers>
                    <pattern>
                        <pattern>
                            {
                             "level": "%level",
                            "logger": "%logger{36}",
                            "message": "%message",
                            "stack":"%exception"
                            }
                        </pattern>
                    </pattern>
                </providers>
            </encoder>
        </appender>
Monish Das
  • 383
  • 2
  • 12
  • 28
  • hi, perhaps use [`Actuator`](https://stackoverflow.com/questions/33744875/spring-boot-how-to-log-all-requests-and-responses-with-exceptions-in-single-pl). you could also use `HttpServletResponse.getStatus()` after the status is set. – IronMan Dec 09 '20 at 00:04
  • 1
    How can I set that in xml? – Monish Das Dec 09 '20 at 01:26

0 Answers0