I am interested in using slf4j-logback
in my project, and would like to use the DBAppender
.
Apparently, unless you implement your own DBNameResolver
, you must abide by the specific table criteria/schema outlined in the link above. Specifically, you need 3 tables with very specific columns.
Although the information on that page is fairly verbose, it doesn't include any "table metadata" (keys, indexes, default values, etc.) and I'm wondering if we're left to add those at our own discretion or if they need to be defined with specific values.
I tried looking for a DDL or SQL script for creating these tables, but couldn't find any. Do such scripts exist? How have other SOers dealt with the creation of these DBAppender
tables? Thanks in advance!
Edit: I found this article on Grails discussing DBAppender
:
You must create the database tables yourself. There are three tables, and the Logback distribution ships with sample DDL for several popular databases.
I downloaded the latest (1.0.13) distribution and searched it high and low for .ddl and .sql files, and found something that resembled what I was looking for, located at:
logback-1.0.13/logback-access/src/main/java/ch/qos/logback/access/db/script/mysql.sql
# Logback: the reliable, generic, fast and flexible logging framework.
# Copyright (C) 1999-2010, QOS.ch. All rights reserved.
#
# See http://logback.qos.ch/license.html for the applicable licensing
# conditions.
# This SQL script creates the required tables by ch.qos.logback.access.db.DBAppender.
#
# It is intended for MySQL databases. It has been tested on MySQL 5.0.22 with
# INNODB tables.
BEGIN;
DROP TABLE IF EXISTS access_event_header;
DROP TABLE IF EXISTS access_event;
COMMIT;
BEGIN;
CREATE TABLE ACCESS_EVENT
(
timestmp BIGINT NOT NULL,
requestURI VARCHAR(254),
requestURL VARCHAR(254),
remoteHost VARCHAR(254),
remoteUser VARCHAR(254),
remoteAddr VARCHAR(254),
protocol VARCHAR(254),
method VARCHAR(254),
serverName VARCHAR(254),
postContent VARCHAR(254),
event_id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY
);
COMMIT;
BEGIN;
CREATE TABLE access_event_header
(
event_id BIGINT NOT NULL,
header_key VARCHAR(254) NOT NULL,
header_value VARCHAR(1024),
PRIMARY KEY(event_id, header_key),
FOREIGN KEY (event_id) REFERENCES access_event(event_id)
);
COMMIT;
However these tables (access_event
and access_event_header
) are not the same 3 tables as what the documentation cites (logging_event
, logging_event_property
, and logging_event_exception
). So I'm still at a loss here...
I looked at the source code for 1.0.13's DBAppender
. The Javadocs for the DBAppender
class state:
The DBAppender inserts access events into three database tables in a format independent of the Java programming language.
However when you dig down into the code, the log messages are actually just being appended to access_event_header
and access_event
, not 3 tables like the Javadocs say.
So, in conclusion:
The logback Javadocs and developer docs are not up to date with the latest release, and do not reflect the true table structure that the DBAppender
requires.