Skip to content

Commit

Permalink
added winston logger to api and frontend but some weird issue there
Browse files Browse the repository at this point in the history
  • Loading branch information
Reptudn committed Feb 14, 2025
1 parent 7b41689 commit 53d3039
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 13 deletions.
201 changes: 198 additions & 3 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "tsc -p tsconfig.json",
"start": "node dist/main.js",
"dev": "tsc -w -p tsconfig.json",
"dev": "nodemon --watch . --ext ts --exec ts-node ./src/main.ts",
"test": "jest --detectOpenHandles"
},
"keywords": [],
Expand All @@ -21,7 +21,8 @@
"ejs": "^3.1.10",
"fastify": "^5.2.1",
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7"
"sqlite3": "^5.1.7",
"winston": "^3.17.0"
},
"devDependencies": {
"@types/jest": "^29.5.14",
Expand Down
33 changes: 33 additions & 0 deletions api/src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { createLogger, format, transports } from 'winston';
import path from 'path';

const logFormat = format.printf(({ timestamp, level, message }) => {
return `${timestamp} [${level}]: ${message}`;
});

const logger = createLogger({
level: 'info',
format: format.combine(
format.colorize(),
// format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
logFormat
),
transports: [
new transports.Console({
format: format.combine(
format.colorize(),
format.simple()
)
}),
new transports.File({ filename: path.join(__dirname, '../../logs/error.log'), level: 'error' }),
new transports.File({ filename: path.join(__dirname, '../../logs/combined.log') })
],
exceptionHandlers: [
new transports.File({ filename: path.join(__dirname, '../../logs/exceptions.log') })
],
rejectionHandlers: [
new transports.File({ filename: path.join(__dirname, '../../logs/rejections.log') })
]
});

export default logger;
Loading

0 comments on commit 53d3039

Please sign in to comment.