Send Strapi logs to TimeScaleDB
npm install @octree/strapi-timescale-loggerSend Strapi's logs to TimescaleDB.
1. Create an hypertable in a database:
``sql`
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
.env
2. Set environment variables ( 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
`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,
};
};
``