Zalando logbook with log4j2

1k Views Asked by At

I am trying to introduce Lombook to my project but logging doesn't work. According to documentation servlet filter adding is enough for start working with default setups. I has added servlet to web.xml but logging doesn't work.

<filter>
    <filter-name>LogbookFilter</filter-name>
    <filter-class>org.zalando.logbook.servlet.LogbookFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>LogbookFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ASYNC</dispatcher>
</filter-mapping>

Could you please advise what should I do for logging correct work with tracing to defined file? Should I configure log4j2 for that and if Yes, in what way?

Thanks in advance

1

There are 1 best solutions below

0
Wagner Büttner On

If you use Springboot, go to your application.yml and:

logbook:
  include:
    - /api/**
  exclude:
    - /actuator/health
    - /api/admin/**
  filter.enabled: true
  secure-filter.enabled: true
  format.style: http
  strategy: body-only-if-status-at-least
  minimum-status: 200
  obfuscate:
    headers:
      - Authorization
      - X-Secret
    parameters:
      - access_token
      - password
  write:
    chunk-size: 4096

also I'd like to mention that I'm using Log4j2 and Gelf to send the messages to Graylog