0.2.0 • Published 2 years ago

@octree/strapi-timescale-logger v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@octree/strapi-timescale-logger

Send Strapi's logs to TimescaleDB.

Setup

  1. 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
  2. Set environment variables (.env file can be used):

    LOG_DATABASE_URL=psql://postgres:password@127.0.0.1:5432/logs
    LOG_DATABASE_TABLE=log_client
  3. 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,
       };
     };