如何在非托管扩展中记录到 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!
此页面是否有用?