To create new wiki account, please join us on #znc at Libera.Chat and ask admins to create a wiki account for you. You can say thanks to spambots for this inconvenience.

ZLog SQL

From ZNC
Revision as of 07:47, 21 May 2019 by HaptiK (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This is a global Python module for PostgreSQL/MySQL/SQLite logging.

GitHub repository: https://github.com/stil/zlog-sql

Features

  • Supports PostgreSQL, MySQL, and SQLite databases.
  • Asynchronous database writes on a separate thread. Guarantees that ZNC won't hang during SQL connection timeout.
  • Automatic table creation (CREATE TABLE IF NOT EXIST)
  • Retry after failed inserts. When the database server is offline, logs are buffered to memory. They are saved when the database is back online so you won't lose logs during MySQL outages.

Quick start

  1. Copy zlog_sql.py to ~/.znc/modules/zlog_sql.py.
  2. In Webadmin, open the list of Global Modules.
  3. Make sure modpython is enabled.
  4. Enable module zlog_sql and set its argument.

For PostgreSQL, set module argument matching the following format:

postgres://username:password@localhost/database_name

Important: you need psycopg2 pip package for MySQL logging. Install it with pip3 install psycopg2 command.

For MySQL, set module argument matching the following format:

mysql://username:password@localhost/database_name

Important: you need PyMySQL pip package for MySQL logging. Install it with pip3 install PyMySQL command.

For SQLite use the following string format:

sqlite:///home/user/logs.sqlite

or simply leave out the path

sqlite

in this case, logs are going to be written to the default path ~/.znc/moddata/zlog_sql/logs.sqlite.

  1. Save changes. SQL table schema is going to be created automatically.