public final class DatabaseLogHandler extends AbstractLogHandler implements 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.
import klyn.databases.sql
import klyn.logging.handler
connection = DriverManager.getConnection("mariadb://localhost/logs", "app", "secret")
handler = DatabaseLogHandler(connection, "application_logs")| Modifier and Type | Member | Description |
|---|---|---|
| public | DatabaseLogHandlerDatabaseLogHandler(
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. |
| Modifier and Type | Member | Description |
|---|---|---|
| public override | closeclose() as Void: |
Closes an owned connection. |
| public static | connect | Opens an owned connection and creates a database handler. |
| public override | flushflush() as Void: |
Database statements are executed immediately. |
| public override | handlehandle(event as LogEvent) as Void: |
Inserts one event with a prepared statement. |