Logging
The NuoDB JDBC driver supports the following three types of logger implementations:
-
Standard Logger [Default]
Warnings and errors are logged automatically.
By default, the logging implementation enables INFO level logging which is sufficient to log the DataSource and its configuration when it is created.
For more detailed logging of connections, statements, and result sets in use, enable TRACE level logging.
SLF4J Logger
SLF4J is an abstraction for various logging frameworks, such as java.util.logging, Commons logging, logback, and log4j.
It contains API compatible implementations of the interfaces of all these libraries and then channels all logging to the chosen logging framework to produce output.
This allows developers to select the desired logging framework at deployment time, avoiding conflicts caused by different dependencies requiring different logging libraries at run time.
SLF4J requires a single mandatory dependency, slf4j-api-xxx.jar (where xxx is the version).
However, a logging implementation is also required at runtime.
Any supported logging framework such as Simple Logger or Logback Logger can be used.
NuoDB’s slf4jLogger implements the SLF4J API.
To enable the slf4jLogger, set the slf4jLogger connection property.
For more information, see Connection Properties.
The SLF4J JAR must be on your CLASSPATH if the slf4jLogger connection property is set to true.
Example
public static final String DATABASE_URL = "jdbc:com.nuodb://localhost/test";
/* Using a DataSource */
Properties properties = new Properties();
properties.put("url", DATABASE_URL + "?slf4jLogger=true");
properties.put("user", "dba");
properties.put("password", "dba");
properties.put("schema", "logschema");
try {
DataSource datasource = new DataSource(properties);
...
}
To generate log output, a logging implementation must be configured. If it is not configured, the application will still run without generating logs and the following error is displayed:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Simple Logger
The simplest SLF4J binding available is to include these two libraries on your CLASSPATH (where xxx is the version):
-
slf4j-api-xxx.jar -
slf4j-simple-xxx.jar(which logs directly to the console viaSystem.err()).
To set the logging level to TRACE:
/* In main() BEFORE creating your DataSource */
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel=trace");
Logback Logger
To use Logback:
-
slf4j-api-xxx.jar -
logback-classic.xxx.jar -
logback-core.xxx.jar
To set the logging level to TRACE:
/* BEFORE creating your DataSource */
Logger parent = LoggerFactory.getLogger("com.nuodb.jdbc");
if (parent instanceof ch.qos.logback.classic.Logger) {
((ch.qos.logback.classic.Logger) parent).setLevel(Level.TRACE);
}
For more information on SLF4J bindings, refer to SLF4J documentation.
JDK14 Logger
This directs logging to the standard Java logging API using java.util.logging.Logger.
To use this logger, set the jdk14Logger connection property. For more information, see Connection Properties.
Example
public static final String DATABASE_URL = "jdbc:com.nuodb://localhost/test";
/* Using a DataSource */
Properties properties = new Properties();
properties.put("url", DATABASE_URL + "?jdk14Logger=true");
properties.put("user", "dba");
properties.put("password", "dba");
properties.put("schema", "logschema");
try {
DataSource datasource = new DataSource(properties);
/* Optionally get parent of this logger. Configuring this logger will */
/* affect all loggers used by the driver. Here we enable all logging */
/* at all levels by raising logging level to FINEST. */
Logger parentLogger = datasource.getParentLogger();
parentLogger.setLevel(Level.FINEST);
...
}
To change the default logging level, edit the configuration file (for example, logging.properties) and set the .level property.
Standard Logger
Standard Logger is the default logging option.
It is enabled by default, but only generates output when a PrintWriter is supplied.
-
The Standard Logger uses the
java.io.PrintWriterobtained fromcom.nuodb.jdbc.DataSource.getLogWriter(). -
The logger must be initialized using
com.nuodb.jdbc.DataSource.setLogWriter()or no logging output is generated. -
To use Standard Logger set the
standardLoggerconnection property.
The connection properties related to Standard Logger are standardLogger, standardLogger.level, standardLogger.logWriter and standardLogger.pattern.
For more information, see Connection Properties.
Example
Here is an example of using StandardLogger:
public static final String DATABASE_URL = "jdbc:com.nuodb://localhost/test";
/* Using a DataSource */
String loggingProperties = "?standardLogger=true"
+ "&standardLogger.level=TRACE"
+ "&standardLogger.pattern=[%date] (%level) (%line(long))";
Properties properties = new Properties();
properties.put("url", DATABASE_URL + loggingProperties);
properties.put("user", "dba");
properties.put("password", "dba");
properties.put("schema", "logschema");
try {
DataSource datasource = new DataSource(properties);
datasource.setLogWriter(new PrintWriter(System.out));
...
}