@octree/strapi-timescale-logger
v0.2.0
Published
Send Strapi logs to TimeScaleDB
Downloads
2
Readme
@octree/strapi-timescale-logger
Send Strapi's logs to TimescaleDB.
Setup
Create an hypertable in a database:
CREATE TABLE logs ( timestamp timestamp without time zone DEFAULT now(), level character varying, message character varying, meta json ); SELECT create_hypertable('logs','timestamp'); SELECT add_retention_policy('logs', INTERVAL '3 months'); -- Optional
Set environment variables (
.env
file can be used):LOG_DATABASE_URL=psql://postgres:[email protected]:5432/logs LOG_DATABASE_TABLE=log_client
Configure Strapi to use the logger by editing
config/logger.js
const TimescaleLogger = require("@octree/strapi-timescale-logger"); module.exports = ({ env }) => { const transports = [ new winston.transports.Console({ level: "http", format: winston.format.combine( prettyPrint({ timestamps: "YYYY-MM-DD hh:mm:ss.SSS" }) ), }), ]; if (env("LOG_DATABASE_URL")) { transports.push( new TimescaleLogger({ level: "http", tableName: env("LOG_DATABASE_TABLE"), knexConfig: { client: "pg", connection: env("LOG_DATABASE_URL"), }, }) ); } return { transports, }; };