Logging to a database#
A log target can write each record as a row of a table, in a database that you run. It is for organisations whose own tools read logs from a database, and for those who came from CrushFTP 11 with such a table and the queries around it.
Note
The server needs no database and brings none, and no driver. For most uses a database is not the best place for a log: a log server reached by syslog, or a file that a shipper reads, is simpler to run and built for it. For numbers and lists about what happened, the server's own Reports need nothing at all.
The settings are in Preferences, Logging, Log Targets.
What is written#
One row per record, into one table, with four values:
| Value | Is |
|---|---|
| the time | in milliseconds |
| the tag | the kind of line: POST, STOR, ACCEPT … |
| the record | the log line, or the event |
| a row number | counting up |
What "the record" is depends on the target's Format: the line of CrushMFT.log with the debug format, or the event as CEF, LEEF or JSON with one of the SIEM formats. See SIEM formats.
Setting it up#
- Make the table. The server does not create it. For the statements the form starts with:
CREATE TABLE CRUSHFTP_LOG (
LOG_ROW_NUM BIGINT,
LOG_MILLIS BIGINT,
LOG_TAG VARCHAR(50),
LOG_DATA TEXT
);
Use your database's type for long text: with a JSON format a record is a whole JSON object, and longer than a short text column holds.
-
Put the driver in place. The JDBC driver of your database, a jar file from its maker, goes into
plugins/libin the server's folder. Restart the server once: drivers are loaded when it starts. -
Add the target: Send to Database, then
| Field | Is |
|---|---|
| Database URL | the JDBC address: jdbc:postgresql://db.example.com:5432/logs |
| Driver class | the driver's class: org.postgresql.Driver |
| Driver jar | the file you put into plugins/lib |
| User, Password | an account that may insert into the table, and read its highest row number. Nothing more. |
| Insert | the statement that writes a row. Its four ? are, in this order: the time, the tag, the record, the row number. |
| Last row query | a query for the highest row number so far, so that the numbering goes on after a restart |
- Send Test Record, look for the row, Save.
The two statements are yours to change: other table and column names, a stored procedure, a table per month by a view. Only the order of the four ? is fixed.
When the database is slow, or down#
A log target never holds the server up. Records wait in the target's queue, 10,000 of them, and are written in the background. When the database is down for longer than the queue lasts, further records are dropped and counted. They are still in CrushMFT.log.
That makes a database target a poor fit for a log that must be complete. Where completeness matters, send by syslog over TCP to a log server, and let that load the database, or use the activity record, which waits on disk for its database for as long as it takes: The store in your database.
A busy server at a high debug level writes thousands of lines a second. Each is an insert. Send a database only what somebody will query: level 0, or events in a SIEM format.
Keeping it small#
The server never deletes rows. A job of the database, or of yours, has to: delete by LOG_MILLIS, or keep a table per month and drop old ones.
An index on LOG_MILLIS is what makes queries by time, and that delete, fast.
Coming from CrushFTP 11#
Version 11 had the same idea as a "logging provider" with the same four-column table. A target with Send to Database and the format CrushMFT debug log writes what 11 wrote, into the same table. In CrushMFT 27 a change of the settings counts within seconds; 11 needed a restart.
Things to know#
- The password is stored encrypted.
- In FIPS mode, a database driver brings cryptography of its own that the mode does not cover: see FIPS mode before using one.
- Several servers can write to one table. The row numbers of each server count on their own, so do not rely on them being unique: add a column for the host by a default or a view if you need to tell servers apart.
- Not the user database. This table is a log and nothing else; give its account no rights elsewhere.