From 3baa4dc89335065b777ff831240dbec51c7f7782 Mon Sep 17 00:00:00 2001 From: Glemen Neo Date: Tue, 17 Sep 2024 02:27:53 +0800 Subject: [PATCH] [#7] feat: add logging --- .gitignore | 2 ++ backend/user-service/src/server.ts | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9da91d0e6f..f7922c71b3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ **/dist **/coverage +**/*.log + **/.turbo \ No newline at end of file diff --git a/backend/user-service/src/server.ts b/backend/user-service/src/server.ts index 93c7539abb..1414a41af8 100644 --- a/backend/user-service/src/server.ts +++ b/backend/user-service/src/server.ts @@ -1,11 +1,24 @@ import 'dotenv/config' import http, { Server } from 'http' +import Winston, { Logger } from 'winston' import index from './index' +// Setup Logger +export const logger: Logger = Winston.createLogger({ + level: 'info', + format: Winston.format.json(), + defaultMeta: { service: 'user-service' }, + transports: [ + new Winston.transports.Console(), + new Winston.transports.File({ filename: 'error.log', level: 'error' }), + new Winston.transports.File({ filename: 'combined.log' }), + ], +}) + const port: string = process.env.PORT ?? '3000' const server: Server = http.createServer(index) server.listen(port, async () => { - console.log(`Server is listening on port ${port}`) + logger.info(`[Init] Server is listening on port ${port}`) })