From 9b24bd0c41680a25d054134df0927c3f65aa003d Mon Sep 17 00:00:00 2001 From: Maix0 Date: Wed, 17 Dec 2025 19:42:33 +0100 Subject: [PATCH] feat(monitoring): change logger to pino This changes the logger used to be pino, which print the logs on a single line per log event --- src/@shared/src/database/index.ts | 6 ++++-- src/@shared/src/utils/index.ts | 2 +- src/auth/entrypoint.sh | 5 ----- src/auth/src/run.ts | 18 ++---------------- src/chat/entrypoint.sh | 1 - src/chat/src/run.ts | 29 +++++++---------------------- src/user/entrypoint.sh | 1 - src/user/src/run.ts | 18 ++---------------- 8 files changed, 16 insertions(+), 64 deletions(-) diff --git a/src/@shared/src/database/index.ts b/src/@shared/src/database/index.ts index ea111db..981a40d 100644 --- a/src/@shared/src/database/index.ts +++ b/src/@shared/src/database/index.ts @@ -28,8 +28,10 @@ export const useDatabase = fp(async function( if (dbAdded) { return; } dbAdded = true; const path = process.env.DATABASE_DIR; - if (isNullish(path)) { throw 'env `DATABASE_DIR` not defined'; } - f.log.info(`Opening database with path: ${path}/database.db`); + if (isNullish(path)) { + f.log.fatal('env `DATABASE_DIR` not defined'); + throw 'env `DATABASE_DIR` not defined'; + } const db: Database = new DbImpl(`${path}/database.db`) as Database; if (!f.hasDecorator('db')) { f.decorate('db', db); } }); diff --git a/src/@shared/src/utils/index.ts b/src/@shared/src/utils/index.ts index a79cbe9..745bbfc 100644 --- a/src/@shared/src/utils/index.ts +++ b/src/@shared/src/utils/index.ts @@ -11,7 +11,7 @@ import { FastifyReply } from 'fastify'; import fp from 'fastify-plugin'; export const useMonitoring = fp(async (fastify) => { - fastify.get('/monitoring', { schema: { hide: true } }, (req, res) => { + fastify.get('/monitoring', { schema: { hide: true }, logLevel: 'silent' }, (req, res) => { void req; res.code(200).send('Ok'); }); diff --git a/src/auth/entrypoint.sh b/src/auth/entrypoint.sh index a5c6509..f1735d5 100644 --- a/src/auth/entrypoint.sh +++ b/src/auth/entrypoint.sh @@ -1,12 +1,7 @@ #!/bin/sh set -e -set -x # do anything here -mkdir -p /volumes/static/auth/ -cp -r /extra/login_demo.html /volumes/static/auth/index.html -cp -r /extra/login_demo.js /volumes/static/auth/login_demo.js - # run the CMD [ ... ] from the dockerfile exec "$@" diff --git a/src/auth/src/run.ts b/src/auth/src/run.ts index d3d410f..3c59d5d 100644 --- a/src/auth/src/run.ts +++ b/src/auth/src/run.ts @@ -4,23 +4,9 @@ import fastify, { FastifyInstance } from 'fastify'; import app from './app'; const start = async () => { - const envToLogger = { - development: { - transport: { - target: 'pino-pretty', - options: { - translateTime: 'HH:MM:ss Z', - ignore: 'pid,hostname', - }, - }, - }, - production: true, - test: false, - }; - - const f: FastifyInstance = fastify({ logger: envToLogger.development }); + const f: FastifyInstance = fastify({ logger: { level: 'info' } }); process.on('SIGTERM', () => { - f.log.info('Requested to shutdown'); + f.log.warn('Requested to shutdown'); process.exit(134); }); try { diff --git a/src/chat/entrypoint.sh b/src/chat/entrypoint.sh index 2dcab02..f1735d5 100644 --- a/src/chat/entrypoint.sh +++ b/src/chat/entrypoint.sh @@ -1,7 +1,6 @@ #!/bin/sh set -e -set -x # do anything here # run the CMD [ ... ] from the dockerfile diff --git a/src/chat/src/run.ts b/src/chat/src/run.ts index d9f1e2a..3c59d5d 100644 --- a/src/chat/src/run.ts +++ b/src/chat/src/run.ts @@ -4,33 +4,18 @@ import fastify, { FastifyInstance } from 'fastify'; import app from './app'; const start = async () => { - const envToLogger = { - development: { - transport: { - target: 'pino-pretty', - options: { - translateTime: 'HH:MM:ss Z', - ignore: 'pid,hostname', - }, - }, - }, - production: true, - test: false, - }; - - const f: FastifyInstance = fastify({ logger: envToLogger.development }); + const f: FastifyInstance = fastify({ logger: { level: 'info' } }); + process.on('SIGTERM', () => { + f.log.warn('Requested to shutdown'); + process.exit(134); + }); try { - process.on('SIGTERM', () => { - f.log.info('Requested to shutdown'); - process.exit(134); - }); - console.log('-------->Serving static files from:'); await f.register(app, {}); await f.listen({ port: 80, host: '0.0.0.0' }); } catch (err) { f.log.error(err); process.exit(1); - }; + } }; -start(); \ No newline at end of file +start(); diff --git a/src/user/entrypoint.sh b/src/user/entrypoint.sh index 2dcab02..f1735d5 100644 --- a/src/user/entrypoint.sh +++ b/src/user/entrypoint.sh @@ -1,7 +1,6 @@ #!/bin/sh set -e -set -x # do anything here # run the CMD [ ... ] from the dockerfile diff --git a/src/user/src/run.ts b/src/user/src/run.ts index d3d410f..3c59d5d 100644 --- a/src/user/src/run.ts +++ b/src/user/src/run.ts @@ -4,23 +4,9 @@ import fastify, { FastifyInstance } from 'fastify'; import app from './app'; const start = async () => { - const envToLogger = { - development: { - transport: { - target: 'pino-pretty', - options: { - translateTime: 'HH:MM:ss Z', - ignore: 'pid,hostname', - }, - }, - }, - production: true, - test: false, - }; - - const f: FastifyInstance = fastify({ logger: envToLogger.development }); + const f: FastifyInstance = fastify({ logger: { level: 'info' } }); process.on('SIGTERM', () => { - f.log.info('Requested to shutdown'); + f.log.warn('Requested to shutdown'); process.exit(134); }); try {