Logging http request/response with separate timings for each in Neo4j server

这一生的挚爱 提交于 2019-12-07 16:22:00

问题


I wanted to log http request and response to Neo4j server. I searched and got the answer on stackoverflow itself in below question: How to log query statement to Neo4j server, is it possible?

The configuration in the answer to above question results in same time logged for both request/response. I was wondering what that time represents ,i.e, when the server received the request or when it generated the response?

Also, I want to log the request and response with individual time for each(i.e, request with time when server received it and response with time when it was generated)? I tried to add a separate pattern for response but it didn't work:

<pattern>%h %l %user [%t{dd/MMM/yyyy:HH:mm:ss Z}] "%r" %s %b "%i{Referer}" "%i{User-Agent}" \nRequest:\n%fullRequest</pattern>
<pattern>%h %l %user [%t{dd/MMM/yyyy:HH:mm:ss Z}] "%r" %s %b "%i{Referer}" "%i{User-Agent}" \nResponse:\n%fullResponse</pattern>

Any ideas to achieve it?

Regards, Rahul


回答1:


You need to configure three different appenders generating three different patterns, don't know if it is possible to have multiple patterns for the same appender though.

make sure to add this line to your conf/neo4j-server.properties file

org.neo4j.server.http.unsafe.content_log.enabled=true

Here is a neo4j-http-logging.xml example for your needs

    <configuration>
  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>data/log/http.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>data/log/http.%d{yyyy-MM-dd_HH}.log</fileNamePattern>
      <maxHistory>30</maxHistory>
    </rollingPolicy>
    <encoder>
      <!-- Note the deliberate misspelling of "referer" in accordance with RFC1616 -->
      <pattern>%h %l %user [%t{dd/MMM/yyyy:HH:mm:ss Z}] "%r" %s %b "%i{Referer}" "%i{User-Agent}" %D</pattern>
    </encoder>
  </appender>

  <appender name="REQUEST" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>data/log/http.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>data/log/http.%d{yyyy-MM-dd_HH}.log</fileNamePattern>
      <maxHistory>30</maxHistory>
    </rollingPolicy>
    <encoder>
      <!-- Note the deliberate misspelling of "referer" in accordance with RFC1616 -->
      <pattern>%h %l %user [%t{dd/MMM/yyyy:HH:mm:ss Z}] "%r" %s %b "%i{Referer}" "%i{User-Agent}" %D \n%fullRequest</pattern>
    </encoder>
  </appender>

  <appender name="RESPONSE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>data/log/http.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>data/log/http.%d{yyyy-MM-dd_HH}.log</fileNamePattern>
      <maxHistory>30</maxHistory>
    </rollingPolicy>
    <encoder>
      <!-- Note the deliberate misspelling of "referer" in accordance with RFC1616 -->
      <pattern>%h %l %user [%t{dd/MMM/yyyy:HH:mm:ss Z}] "%r" %s %b "%i{Referer}" "%i{User-Agent}" %D \n%fullResponse</pattern>
    </encoder>
  </appender>

  <appender-ref ref="FILE"/>
  <appender-ref ref="REQUEST"/>
  <appender-ref ref="RESPONSE"/>
</configuration>

Restart your Neo4j server



来源:https://stackoverflow.com/questions/29069524/logging-http-request-response-with-separate-timings-for-each-in-neo4j-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!