0

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

  • Afaiks, Logbook uses slfj4 internally, not log4j2. Are you sure that no logs are output? At which location should the log file appear? I skimmed the docs at https://github.com/zalando/logbook but couldn't find something about how the logs are actually written and where. Maybe Logbook is not a good choice? In particular as they state "The Logbook Servlet Filter interferes with downstream code using getWriter and/or getParameter*()." You won't want to have request.getParameter() not working because of that Logbook filter... – gsl Oct 08 '20 at 13:42
  • Problem has been already resolved. The root cause of the problem is incorrect log level in log4j2.xml. After changing it to TRACE or DEBUG logs started output to file set for root logs. So, servlet adding is really enough for start working with zalando logbok. – Dmytro Kolesnyk Oct 10 '20 at 08:28

1 Answers1

0

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

Wagner Büttner
  • 3,799
  • 1
  • 13
  • 12