DatabaseLogHandler
classin packageklyn.logging.handler
public final class DatabaseLogHandler extends AbstractLogHandler implements AutoClosable
└ DatabaseLogHandler
All Implemented Interfaces: AutoClosable

Inserts log events into a SQL table through Klyn's database API.

The target table must expose columns event_time, level, logger, message, fields_json, exception, trace_id and span_id in that order. Schema ownership remains with the application.

Example
import klyn.databases.sql
import klyn.logging.handler

connection = DriverManager.getConnection("mariadb://localhost/logs", "app", "secret")
handler = DatabaseLogHandler(connection, "application_logs")
Inherited Properties
propertyInherited Properties from AbstractLogHandler: minimumLevel
Constructors
Modifier and Type Member Description
public DatabaseLogHandler
DatabaseLogHandler( connection as Connection, table as String = "application_logs", minimumLevel as LogLevel = LogLevel.TRACE, ownsConnection as Boolean = false )
Creates a database handler from an existing connection.
Methods
Modifier and Type Member Description
public override close
close() as Void
Closes an owned connection.
public static connect
connect( url as String, login as String = "", password as String = "", table as String = "application_logs", minimumLevel as LogLevel = LogLevel.TRACE ) as DatabaseLogHandler
Opens an owned connection and creates a database handler.
public override flush
flush() as Void
Database statements are executed immediately.
public override handle
handle(event as LogEvent) as Void
Inserts one event with a prepared statement.
Inherited Methods
methodInherited Methods from AbstractLogHandler: accepts, close, flush, handle
methodInherited Methods from AutoClosable: close
methodInherited Methods from LogHandler: accepts, flush, handle