Package org.rocksdb

Class Logger

All Implemented Interfaces:
AutoCloseable, LoggerInterface

public abstract class Logger extends RocksCallbackObject implements LoggerInterface

This class provides a custom logger functionality in Java which wraps RocksDB logging facilities.

Using this class RocksDB can log with common Java logging APIs like Log4j or Slf4j without keeping database logs in the filesystem.

Performance

There are certain performance penalties using a Java Logger implementation within production code.

A log level can be set using Options or setInfoLogLevel(InfoLogLevel). The set log level influences the underlying native code. Each log message is checked against the set log level and if the log level is more verbose as the set log level, native allocations will be made and data structures are allocated.

Every log message which will be emitted by native code will trigger expensive native to Java transitions. So the preferred setting for production use is either InfoLogLevel.ERROR_LEVEL or InfoLogLevel.FATAL_LEVEL.

  • Constructor Details

    • Logger

      @Deprecated public Logger(Options options)
      Deprecated.
      Use Logger(InfoLogLevel) instead, e.g. new Logger(options.infoLogLevel()).

      AbstractLogger constructor.

      Important: the log level set within the Options instance will be used as maximum log level of RocksDB.

      Parameters:
      options - Options instance.
    • Logger

      @Deprecated public Logger(DBOptions dboptions)
      Deprecated.
      Use Logger(InfoLogLevel) instead, e.g. new Logger(dbOptions.infoLogLevel()).

      AbstractLogger constructor.

      Important: the log level set within the DBOptions instance will be used as maximum log level of RocksDB.

      Parameters:
      dboptions - DBOptions instance.
    • Logger

      public Logger(InfoLogLevel logLevel)

      AbstractLogger constructor.

      Parameters:
      logLevel - the log level.
  • Method Details

    • initializeNative

      protected long initializeNative(long... nativeParameterHandles)
      Description copied from class: RocksCallbackObject
      Construct the Native C++ object which will callback to our object methods
      Specified by:
      initializeNative in class RocksCallbackObject
      Parameters:
      nativeParameterHandles - An array of native handles for any parameter objects that are needed during construction
      Returns:
      The native handle of the C++ object which will callback to us
    • setInfoLogLevel

      public void setInfoLogLevel(InfoLogLevel logLevel)
      Description copied from interface: LoggerInterface
      Set the log level.
      Specified by:
      setInfoLogLevel in interface LoggerInterface
      Parameters:
      logLevel - the level at which to log.
    • infoLogLevel

      public InfoLogLevel infoLogLevel()
      Description copied from interface: LoggerInterface
      Get the log level
      Specified by:
      infoLogLevel in interface LoggerInterface
      Returns:
      the level at which to log.
    • getNativeHandle

      public long getNativeHandle()
      Description copied from interface: LoggerInterface
      Get the underlying Native Handle.
      Specified by:
      getNativeHandle in interface LoggerInterface
      Returns:
      the native handle.
    • getLoggerType

      public final LoggerType getLoggerType()
      Description copied from interface: LoggerInterface
      Get the type of this logger.
      Specified by:
      getLoggerType in interface LoggerInterface
      Returns:
      the type of this logger.
    • log

      protected abstract void log(InfoLogLevel logLevel, String logMsg)
    • newLogger

      protected long newLogger(long logLevel)
    • setInfoLogLevel

      protected void setInfoLogLevel(long handle, byte logLevel)
    • infoLogLevel

      protected byte infoLogLevel(long handle)
    • disposeInternal

      protected void disposeInternal()
      We override RocksCallbackObject.disposeInternal() as disposing of a rocksdb::LoggerJniCallback requires a slightly different approach as it is a std::shared_ptr.
      Overrides:
      disposeInternal in class RocksCallbackObject