Interface Logging

All Known Implementing Classes:
ConsoleLogging, DevNullLogging, JULogging, Slf4jLogging

public interface Logging
Accessor for Logger instances. Configured once for a driver instance using Config.ConfigBuilder.withLogging(Logging) builder method. Users are expected to either implement this interface or use one of the existing implementations (available via static methods in this interface):
  • SLF4J logging - uses available SLF4J binding (Logback, Log4j, etc.) fails when no SLF4J implementation is available. Uses application's logging configuration from XML or other type of configuration file. This logging method is the preferred one and relies on the SLF4J implementation available in the classpath or modulepath.
  • Java Logging API (JUL) - uses Logger created via Logger.getLogger(String). Global java util logging configuration applies. This logging method is suitable when application uses JUL for logging and explicitly configures it.
  • Console logging - uses ConsoleHandler with the specified logging level to print messages to System.err. This logging method is suitable for quick debugging or prototyping.
  • No logging - implementation that discards all logged messages. This logging method is suitable for testing to make driver produce no output.

Driver logging API defines the following log levels: ERROR, INFO, WARN, DEBUG and TRACE. They are similar to levels defined by SLF4J but different from log levels defined for java.util.logging. The following mapping takes place:

Driver and JUL log levels
Driver java.util.logging
ERROR SEVERE
INFO INFO, CONFIG
WARN WARNING
DEBUG FINE, FINER
TRACE FINEST

Example of driver configuration with SLF4J logging:

 
 Driver driver = GraphDatabase.driver("neo4j://localhost:7687",
                                         AuthTokens.basic("neo4j", "password"),
                                         Config.builder().withLogging(Logging.slf4j()).build());
 
 
See Also:
  • Method Details

    • getLog

      default Logger getLog(Class<?> clazz)
      Obtain a Logger instance by class, its name will be the fully qualified name of the class.
      Parameters:
      clazz - class whose name should be used as the Logger name.
      Returns:
      Logger instance
    • getLog

      Logger getLog(String name)
      Obtain a Logger instance by name.
      Parameters:
      name - name of a Logger
      Returns:
      Logger instance
    • slf4j

      static Logging slf4j()
      Create logging implementation that uses SLF4J.
      Returns:
      new logging implementation.
      Throws:
      IllegalStateException - if SLF4J is not available.
    • javaUtilLogging

      static Logging javaUtilLogging(Level level)
      Create logging implementation that uses java.util.logging.
      Parameters:
      level - the log level.
      Returns:
      new logging implementation.
    • console

      static Logging console(Level level)
      Create logging implementation that uses java.util.logging to log to System.err.
      Parameters:
      level - the log level.
      Returns:
      new logging implementation.
    • none

      static Logging none()
      Create logging implementation that discards all messages and logs nothing.
      Returns:
      new logging implementation.