libLogit

SQL Inspection And Viewer Workflow

libLogit is not only about writing logs. The Alpha and Beta product direction is that logs should still be useful after the process exits.

Today, the Python reference binding proves that story with a local SQLite store and the liblogit-viewer tool.

What This Workflow Is For

Use the SQLite plus viewer workflow when you want:

Minimal Database Setup

Enable the database sink and point it at a local SQLite file:

{
  "name": "AuditLog",
  "databasePath": "logs/audit.sqlite",
  "sinks": ["console", "database"],
  "retention": {
    "maxRecords": 10000
  }
}

Or do the same thing directly in Python:

from liblogit import INFO, LOGIT

AuditLog = LOGIT({
    "name": "AuditLog",
    "databasePath": "logs/audit.sqlite",
    "sinks": ["console", "database"],
    "retention": {"maxRecords": 10000},
})

AuditLog.log(INFO, "database-backed event")

Example Script

The repository includes a direct example:

That script:

  1. creates a direct SQLite-backed LOGIT
  2. loads a config-backed SQLite LOGIT
  3. queries recent rows back with Python sqlite3

What The Store Contains

The current Alpha SQLite store is intended to be queried with standard SQL tools. The important working assumption for Beta docs is simple:

The deeper schema contract continues to live in spec/log-store.md and the Python implementation.

Useful Starter Queries

These queries are meant to get a developer oriented quickly.

Most Recent Events

SELECT sequence, created_at, logger, level, message
FROM logit_events
ORDER BY sequence DESC
LIMIT 25;

Events For One Logger

SELECT created_at, logger, level, message
FROM logit_events
WHERE logger = 'AuditLog'
ORDER BY sequence DESC
LIMIT 50;

Errors And Fatals

SELECT created_at, logger, level, message
FROM logit_events
WHERE level IN ('error', 'fatal')
ORDER BY sequence DESC;

Search Message Text

SELECT created_at, logger, level, message
FROM logit_events
WHERE message LIKE '%signed in%'
ORDER BY sequence DESC;

Inspect Stored Metadata

SELECT created_at, logger, level, metadata_json
FROM logit_events
WHERE metadata_json IS NOT NULL
ORDER BY sequence DESC
LIMIT 25;

Opening The Store With SQLite Tooling

Any SQLite-capable tool should work. Common choices include:

The product point is that libLogit should not require a special server or cloud service just to read local retained logs.

Opening The Store With liblogit-viewer

The current Python reference package also exposes a viewer command:

liblogit-viewer logs/audit.sqlite

There is also a query-friendly CLI mode:

python -m liblogit.viewer logs/audit.sqlite --print --level info --limit 20

The viewer direction for Beta is:

Retention Notes

The current Python reference implementation supports bounded retention for the SQLite sink with:

Those settings are the current Alpha proof of the “round robin” retained-store idea: keep the most useful recent history and evict older data according to a defined policy.

Current Scope And Limits

Be plain about the current state:

Next Reading