Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-22-2018 07:38 PM
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:
import org.neo4j.logging.Log;
@Context Log log
as an argument:@GET
@Path("/friendOfFriend/{userId}")
public Response getFofs(@PathParam("userId") String userId, @Context GraphDatabaseService db, @Context Log log) throws IOException {
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!
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!");
}
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!
11-05-2019 01:42 PM
Okay, got that rolling no problem, but what about writing to a different filename?
It looks like Configuration Settings allow for changing the path and filename of an existing logger, but what about rolling my own?
I'm assuming I'll have to implement my own Logger and PrintWriter for that, but I though I'd ask.
11-14-2019 02:17 PM
Hi Tony,
I don't know how off the top of my head, but I am asking around and will come back with what I find out.
Thanks, Dave
11-15-2019 06:24 AM
Hi Tony,
Advice from the experts is that you need to open a new log file. If you want to have a similar format as neo4j.log, look at https://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/logging/FormattedLog.html which is the one we use for neo4j.log and debug.log
I hope that helps!
Thanks, Dave G
11-18-2019 12:54 PM
Thank you David, that is very helpful!
-Tony
All the sessions of the conference are now available online