如何将查询语句记录到 Neo4j 服务器,这可能吗? [英] How to log query statement to Neo4j server, is it possible?

查看:15
本文介绍了如何将查询语句记录到 Neo4j 服务器,这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将整个查询语句记录到 Neo4j 服务器,但是,在搜索 SO & 之后我没有成功的文档.我发现了这个问题,在 Neo4j 服务器上记录的休息查询,但是更改这些配置设置并没有达到我所希望的.我在 Golang & 工作使用 Go-CQ 库与 Neo4j 2.1.5 版中的 REST API 进行通信.

我正在寻找的是正在执行的实际查询,理想情况下还传递了参数.是否可以记录这些信息?任何帮助将不胜感激,谢谢!

解决方案

以下是关于 http 日志记录,也包括查询 + 参数 + 结果.它不适用于仅用于调试和测试的生产设置.

这应该从 2.1.6 开始工作,请参阅:https://github.com/neo4j/neo4j/pull/3399

目前通过设置启用:

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

除了设置:

 org.neo4j.server.http.log.enabled=true

conf/neo4j-server.properties 中,并通过扩充模式 (conf/neo4j-http-logging.xml) 来输出完整的请求和响应:

 %fullRequest

%fullResponse

conf/neo4j-http-logging.xml中的完整部分

<预><代码><配置><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><编码器><!-- 请注意根据 RFC1616 故意拼错referer"--><pattern>%h %l %user [%t{dd/MMM/yyyy:HH:mm:ss Z}] "%r" %s %b "%i{Referer}" "%i{User-Agent}" 请求: %fullRequest 响应: %fullResponse</pattern></编码器></appender><appender-ref ref="文件"/></配置>

这将产生一个 data/log/http.log 文件,内容如下:

127.0.0.1 - - [04/Jan/2015:11:23:50 +0100] "POST/db/data/transaction/commit HTTP/1.1" 200 372 "http://localhost:7474/browser/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"要求:POST/db/data/transaction/commit HTTP/1.1来源:http://localhost:7474X 流:真实Cookie:SQLiteManager_currentLangue=4;__jrDevToolbarSessionId=0x1.b6e143f2c334p-3;JSESSIONID=1AFCE7DCF2D5D7134E933871EBF88252;OSESSIONID=OS1412075842834-2614241454738785158;connect.sid=s%3AkRY6%2B4RyW%2FC2ZUMjfIVqtRRo.shdI5G0zTKSq%2BzKevgXzLEdHnwjUDYP1JFlOhupRf2I;_ga=GA1.1.149316633.1397859613;_mkto_trk=id:773-GON-065&token:_mch-localhost-1384123755719-53900;未定义=0;__atuvc=0%7C47%2C0%7C48%2C1%7C49%2C5%7C50%2C13%7C51接受:应用程序/json、文本/纯文本、*/*连接:保持连接用户代理:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36引用:http://localhost:7474/browser/主机:本地主机:7474DNT:1接受编码:gzip、deflate接受语言:en-US,en;q=0.8,de-DE;q=0.6,de;q=0.4内容长度:115内容类型:application/json;charset=UTF-8{"statements":[{"statement":"match (n) return count(*)","re​​sultDataContents":["row","graph"],"includeStats":true}]}回复:HTTP/1.1 200 正常访问控制允许来源:*内容类型:应用程序/json{"results":[{"columns":["count(*)"],"data":[{"row":[0],"graph":{"nodes":[],"relationships":[]}}],"stats":{"contains_updates":false,"nodes_created":0,"nodes_deleted":0,"properties_set":0,"relationships_created":0,"relationship_deleted":0,"labels_ added":0,"labels_removed":0,"indexes_ added":0,"indexes_removed":0,"constraints_ added":0,"constraints_removed":0}}],"errors":[]}

I would like to log the entire query statement to the Neo4j server, however, after searching SO & the docs I have been unsuccessful. I found this SO question, Rest Queries Logged on Neo4j Server, but changing these configuration settings has not achieved what I had hoped. I am working in Golang & using the Go-CQ library to communicate with the REST API in Neo4j version 2.1.5.

What I am looking for is the actual query that is being executed, ideally with the parameters being passed as well. Is it possible to log this information? Any help would be greatly appreciated, thank you!

解决方案

The following is about http logging which also includes queries + params + results. It is not intended for production settings just debugging and testing.

This should work from 2.1.6, see: https://github.com/neo4j/neo4j/pull/3399

This is currently enabled by setting:

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

besides setting:

 org.neo4j.server.http.log.enabled=true

In conf/neo4j-server.properties, and by augmenting the pattern (conf/neo4j-http-logging.xml) to output full requests and responses:

 <pattern>%fullRequest

%fullResponse</pattern>

Full section in conf/neo4j-http-logging.xml

<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}" 
Request:
%fullRequest
Response:
%fullResponse</pattern>
    </encoder>
  </appender>

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

Which will result in an data/log/http.log file, with content like this:

127.0.0.1 - - [04/Jan/2015:11:23:50 +0100] "POST /db/data/transaction/commit HTTP/1.1" 200 372 "http://localhost:7474/browser/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36" 
Request:
POST /db/data/transaction/commit HTTP/1.1
Origin: http://localhost:7474
X-stream: true
Cookie: SQLiteManager_currentLangue=4; __jrDevToolbarSessionId=0x1.b6e143f2c334p-3; JSESSIONID=1AFCE7DCF2D5D7134E933871EBF88252; OSESSIONID=OS1412075842834-2614241454738785158; connect.sid=s%3AkRY6%2B4RyW%2FC2ZUMjfIVqtRRo.shdI5G0zTKSq%2BzKevgXzLEdHnwjUDYP1JFlOhupRf2I; _ga=GA1.1.149316633.1397859613; _mkto_trk=id:773-GON-065&token:_mch-localhost-1384123755719-53900; undefined=0; __atuvc=0%7C47%2C0%7C48%2C1%7C49%2C5%7C50%2C13%7C51
Accept: application/json, text/plain, */*
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
Referer: http://localhost:7474/browser/
Host: localhost:7474
DNT: 1
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,de-DE;q=0.6,de;q=0.4
Content-Length: 115
Content-Type: application/json;charset=UTF-8

{"statements":[{"statement":"match (n) return count(*)","resultDataContents":["row","graph"],"includeStats":true}]}
Response:
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: application/json

{"results":[{"columns":["count(*)"],"data":[{"row":[0],"graph":{"nodes":[],"relationships":[]}}],"stats":{"contains_updates":false,"nodes_created":0,"nodes_deleted":0,"properties_set":0,"relationships_created":0,"relationship_deleted":0,"labels_added":0,"labels_removed":0,"indexes_added":0,"indexes_removed":0,"constraints_added":0,"constraints_removed":0}}],"errors":[]}

这篇关于如何将查询语句记录到 Neo4j 服务器,这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆