Class DBHandler


  • public class DBHandler
    extends Handler
    DBHandler takes log messages from the Logger and exports them to a specified Database. DBHandler reads LogManager's configuration to get information about Database userid, password, Database Driver, Database location. It takes from the caller the table name which will be created if it doesn't already exists.

    By default DBFormatter is used for formatting the logRecords.

    • Constructor Detail

      • DBHandler

        public DBHandler​(String tableName)
        Constructor takes the tableName as a parameter. Gets the configuration information from LogManager regarding the user name, password, database driver, the log location. Gets the formatter class from the configuration, loads it and sets it as default Formatter. Connects to the database using the username and password. If the table by that name doesnot exists, creates the table.
        Parameters:
        tableName - Database table name for logger.
    • Method Detail

      • publish

        public void publish​(LogRecord logRecord)
        Publishes the provided LogRecord.
        Specified by:
        publish in class Handler
        Parameters:
        logRecord - the log record to be published.
      • nonBlockingFlush

        protected void nonBlockingFlush()
        Flush any buffered messages.
      • flush

        public void flush()
        Specified by:
        flush in class Handler
      • close

        public void close()
        Flush any buffered messages and close the current output stream.
        Specified by:
        close in class Handler