Logging

NuoDB supports three types of Loggers:

StandardLogger

The StandardLogger uses the java.io.PrintWriter obtained from DriverManager#getLogWriter(), DriverManager#setLogWriter(), com.nuodb.jdbc.DataSource#getLogWriter(), or com.nuodb.jdbc.DataSource#setLogWriter(). To use StandardLogger set the standardLogger connection property. The connection properties related to StandardLogger are:

Connection Property Possible Values Description Default Value
StandardLogger true | false Enables or disables logging to PrintWriter obtained from DriverManager.getLogWriter() true
standardLogger.level OFF | ERROR | WARN | INFO | DEBUG | TRACE Sets the logging level INFO
standardLogger.pattern pattern

Sets the message format for logging. Message pattern can include several placeholders which will be expanded at runtime:

  • %level outputs log level
  • %date(dateFormatStyle) produces current timestamp formatted to dateFormatStyle or default "yyyy-MM-dd HH:mm:ss.SSS", if dateFormatStyle is not specified
  • %line(short|long|traceFormatStyle) outputs stack trace element. (traceFormatStyle can be built from any combination of {className}, {methodName}, {shortClassName}, {lineNumber} placeholders)
  • %message prints logging message.
[%date(yyyy-MM-dd HH:mm:ss.SSS)] (%level) (%line(long)) - %message

Example

Here is an example of the user of StandardLogger:

        Connection con = null;
        Properties properties = new Properties();
        properties.put("user", "dba");
        properties.put("password", "dba");
        properties.put("schema", "logschema");
        properties.put("standardLogger", "true");
        properties.put("standardLogger.level", "DEBUG");
        properties.put("standardLogger.pattern", "[%date] (%level) (%line(long))");
        try {
            String url = "jdbc:com.nuodb://localhost/test";
            Class.forName("com.nuodb.jdbc.Driver");
            con = DriverManager.getConnection(url, properties);
            DriverManager.setLogWriter(new PrintWriter(System.out));
...

Jdk14Logger

Directs traces to the standard Java logging API in java.util.logging.Logger. The logging API is part of J2SE as of JDK 1.4, and it ships with the JDK. To use this logger simply set the jdk14Logger connection property:

Connection Property Possible Values Description Default Value
jdk14Logger true | false Enables or disables logging to java.util.logging.Logger false

Example

Connection con = null;
        Properties properties = new Properties();
        properties.put("user", "dba");
        properties.put("password", "dba");
        properties.put("schema", "logschema");
        properties.put("jdk14Logger", "true");
        try {
            String url = "jdbc:com.nuodb://localhost/test";
            Class.forName("com.nuodb.jdbc.Driver");
            con = DriverManager.getConnection(url, properties);
            Logger parentLogger = DriverManager.getDriver(url).getParentLogger();
...

Slf4JLogger

The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks, such as java.util.logging, logback and log4j. The NuoDB Slf4JLogger implements the SLF4J API. SLF4J allows the end-user to plug in the desired logging framework at deployment time. Note that SLF4J-enabling your library/application implies the addition of only a single mandatory dependency, slf4j-api-1.7.12.jar. To use the Slf4JLogger, simply set the slf4jLogger connection property:

Connection Property Possible Values Description Default Value
slf4jLogger true | false Attempts to load and activate SLF4J facade. false

Example

        Connection con = null;
        Properties properties = new Properties();
        properties.put("user", "dba");
        properties.put("password", "dba");
        properties.put("schema", "logschema");
        properties.put("slf4jLogger", "true");
        try {
            String url = "jdbc:com.nuodb://localhost/test";
            Class.forName("com.nuodb.jdbc.Driver");
            con = DriverManager.getConnection(url, properties); 
...

With slf4j-api-1.7.12.jar on your CLASSPATH you can run your Java app with the slf4jLogger connection property set to true. Without any slf4j binding set, you will get this error:

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.

The simplest slf4j binding you can add is to include these libraries on your CLASSPATH:

For more information on SLF4J bindings refer to the SLF4J documentation at http://www.slf4j.org/manual.html.