如何在非托管扩展中记录日志到 neo4j.log
作为 3.0 重大改动的一部分,记录到用户日志(现在在服务器模式下为 neo4j.log)的方式已经改变。在非托管扩展中进行日志记录相当简单。
-
引入这个包:
import org.neo4j.logging.Log; -
在非托管扩展的方法中,添加
@Context Log log作为参数。
@GET
@Path("/friendOfFriend/{userId}")
public Response getFofs(@PathParam("userId") String userId, @Context GraphDatabaseService db, @Context Log log) throws IOException {
-
随后使用
log对象的相应方法进行记录。
// Method variables
try (Transaction tx = db.beginTx()) {
// Get the user node
final Node user = db.findNode(Labels.Person, "userId");
// Let's write that to neo4j.log!
log.info("Found user node: " + user.toString());
// Code to find fofs, and build result set formatted
}
// Return results, which are contained in method variable "results"
return Response.ok().entity(objectMapper.writeValueAsString(results)).build();
// Let's write to neo4j.log again!
log.debug("We are all done!");
}
我们得到的日志包含如下行。
2016-12-05 17:33:21.223+0000 INFO Found user node: Node[63564] 2016-12-05 17:33:21.345+0000 DEBUG We are all done!
此页面有帮助吗?