As part of the major changes in 3.0, the way to log to the user log, now neo4j.log (in server mode), has changed. To log within an Unmanaged Extension is quite straightforward:

  1. Include this package: import org.neo4j.logging.Log;
  2. In the method for the Unmanaged Extension, include @Context Log log as an argument:
public Response getFofs(@PathParam("userId") String userId, @Context GraphDatabaseService db, @Context Log log) throws IOException {
  1. Now log using the appropriate method for the log object:
       // 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!
  "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!");

We get a log that contains lines like this:

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!


Dave Gordon
Applicable versions:
3.0, 3.1
extensionJava APIloggingneo4j-3.0neo4j-3.1