Tweak logging of standalone Neo4j server

Viewed 169

When running the Neo4j standalone community Docker, some logs are written to stdout and some to a file inside the container: debug.log.

I would like to be able to set log4j options, like log-level, appenders etc. The reasons are:

  • I can't access the log files when running in e.g AWS ECS
  • The debug logs are quite verbose
  • log4j-properties are convenient to deploy and manage

So the question is, how can I set a custom log4j properties for a Neo4j server that's running inside a container?

It's not documented if it's even possible, but I have tried the usual things one starts to thing of. First adding a log4j.xml to the classpath but to no avail. Also I have tried setting dbms.jvm.additional to

  • -Dlog4j.configuration=<path_to_file>
  • -Dlog4j.configurationFile=<path_to_file>
  • -Dlog4j2.configurationFile==<path_to_file>

I've verified that the Neo4j process has the correct jvm-arguments:

/usr/local/openjdk-11/bin/java -cp /var/lib/neo4j/plugins:/var/lib/neo4j/conf:/var/lib/neo4j/lib/*:/var/lib/neo4j/plugins/* 
-Xms2048m -Xmx2048m -XX:+UseG1GC -XX:-OmitStackTraceInFastThrow -XX:+AlwaysPreTouch 
-XX:+UnlockExperimentalVMOptions -XX:+TrustFinalNonStaticFields -XX:+DisableExplicitGC 
-XX:MaxInlineLevel=15 -XX:-UseBiasedLocking -Djdk.nio.maxCachedBufferSize=262144 
-Dio.netty.tryReflectionSetAccessible=true -Djdk.tls.ephemeralDHKeySize=2048 
-Djdk.tls.rejectClientInitiatedRenegotiation=true -XX:FlightRecorderOptions=stackdepth=256 
-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -Dlog4j2.disable.jmx=true 
-Dlog4j.configuration=file:/var/lib/neo4j/conf/log4j.properties 
-Dlog4j.configurationFile=file:/var/lib/neo4j/conf/log4j.xml 
-Dlog4j2.configurationFile=file:/var/lib/neo4j/conf/log4j2.xml 
-Dfile.encoding=UTF-8 org.neo4j.server.CommunityEntryPoint 
--home-dir=/var/lib/neo4j --config-dir=/var/lib/neo4j/conf

I have verified that no lib-jars contains a log4j-properties that takes precedence.

And whatever I try, no changes are made to the way the server is logging. The same events are written to /logs/debug.log. No exceptions regarding bad log4j config or something like that.

I have created a small project for easier debugging.

1 Answers

I would write out the files to stdout.

# forward logs to docker log collector
RUN ln -sf /dev/stdout /logs/debug.log

So this is a 'docker' solution but handy and works also for other usecases.

Related