Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j logging from a Neo4j server extension

Tags:

log4j

neo4j

My unmanaged server extension uses slf4j-log4j logging. When log4j.properties is bundled with the extension, logging works fine. When it's not bundled but instead placed in Neo4j's conf directory, I assumed

wrapper.java.additional=-Dlog4j.configuration=file:conf/log4j.properties

from neo4j-wrapper.conf would ensure that it's picked up. However, I don't see the log file being created or the specified log level being used. The config file must be correct because it works as designed when bundled with the extension. Adding -Dlog4j.debug as suggested in other posts adds no further information.

Is there something I've missed? I'm using Neo4j 2.1.3 on Mac OS X

like image 388
Luanne Avatar asked Feb 02 '26 14:02

Luanne


1 Answers

Neo4j internally has the logback jars aboard, so every logging using slf4j will be handled by logback.

My approach to logging from an unmanaged extension is as follows:

Set up your logger in the unmanaged extension have a dependency on slf4j-api (do not add and other slf4j implementations to the classpath) and use the logger like this:

 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

 private static final Logger logger = LoggerFactory.getLogger(com.mycompany.UnmanagedExtension.class);

Modify conf/custom-logback.xml and amend at the end:

  <appender name="EXTENSIONLOG"  class="ch.qos.logback.core.FileAppender">
      <file>extensions.log</file>
      <encoder>
          <pattern>%date{yyyy-MM-dd HH:mm:ss.SSSZ} %-5level [%logger{15}]: %message%n</pattern>
      </encoder>
  </appender>

  <logger name="com.mycompany" level="debug">
    <appender-ref ref="EXTENSIONLOG"/>
  </logger>

conf/custom-logback.xml is included by Neo4j's internal logback configuration, see https://github.com/neo4j/neo4j/blob/master/community/kernel/src/main/resources/neo4j-logback.xml

like image 139
Stefan Armbruster Avatar answered Feb 05 '26 08:02

Stefan Armbruster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!