Class DatabaseLogEventObserver

  • All Implemented Interfaces:
    LogEventObserver, LogEventSource

    public class DatabaseLogEventObserver
    extends AbstractBatchingLogEventObserver
    implements LogEventSource
    Writes log events asynchronously to relational database with JDBC. Will create the necessary tables at startup if they don't exist. DatabaseLogEventObserver can use an existing database and doesn't interfere with database migrations with Flyway or similar tools. Log events are written with UUID primary keys and the same database can be used for several applications if you want. This class should work with all relational database providers but has only been verified with Postgres and H2.

    DatabaseLogEventObserver is a nice compromise if you want to take a step towards centralized logging, but don't want to set up Elastic search, Splunk or a similar solution quite yet.

    DatabaseLogEventObserver is designed to be used with LogEventsServlet through WebLogEventObserver

    Sample configuration

     observer.db=DatabaseLogEventObserver
     observer.db.jdbcUrl=jdbc:postgres://localhost/logdb
     observer.db.jdbcUsername=logevents
     observer.db.jdbcPassword=sdgawWWF/)l31L
     observer.db.logeventsTable=log_events
     observer.db.logeventsMdcTable=log_events_mdc
     observer.db.loginTimeout=20
     observer.db.noFetchFirstSupport=false