public interface Logging
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 | 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("bolt://localhost:7687",
AuthTokens.basic("neo4j", "password"),
Config.build().withLogging(Logging.slf4j()).toConfig());
Logger
,
Config.ConfigBuilder.withLogging(Logging)
Modifier and Type | Method and Description |
---|---|
static Logging |
console(Level level)
Create logging implementation that uses
java.util.logging to log to System.err . |
default Logger |
getLog(Class<?> clazz)
Obtain a
Logger instance by class, its name will be the fully qualified name of the class. |
Logger |
getLog(String name)
Obtain a
Logger instance by name. |
static Logging |
javaUtilLogging(Level level)
Create logging implementation that uses
java.util.logging . |
static Logging |
none()
Create logging implementation that discards all messages and logs nothing.
|
static Logging |
slf4j()
Create logging implementation that uses SLF4J.
|
default Logger getLog(Class<?> clazz)
Logger
instance by class, its name will be the fully qualified name of the class.static Logging slf4j()
IllegalStateException
- if SLF4J is not available.static Logging javaUtilLogging(Level level)
java.util.logging
.level
- the log level.static Logging console(Level level)
java.util.logging
to log to System.err
.level
- the log level.static Logging none()