feat: logging

This commit is contained in:
eneller
2026-03-06 01:33:58 +01:00
parent 599ed86c52
commit 6fc751a876
4 changed files with 300 additions and 7 deletions

View File

@@ -22,7 +22,8 @@
"express": "^5.2.1",
"pg": "^8.20.0",
"pg-hstore": "^2.3.4",
"sequelize": "^6.37.7"
"sequelize": "^6.37.7",
"winston": "^3.19.0"
},
"devDependencies": {
"@types/cors": "^2.8.19",

View File

@@ -1,12 +1,9 @@
import express, { Express, Request, Response } from "express";
import cors from "cors";
import * as dotenv from "dotenv";
import transactionsRouter from './routes/transactions';
import { db, testConnection } from "./db";
import { db, testConnection, logger } from "./util";
dotenv.config();
const app: Express = express();
app.use(cors());
app.use(express.json());

View File

@@ -1,4 +1,21 @@
import { Sequelize } from 'sequelize';
import winston, { format } from "winston";
import dotenv from 'dotenv';
dotenv.config();
const logger = winston.createLogger({
level:'info',
})
if (process.env.NODE_ENV !== 'production') {
logger.add(new winston.transports.Console({
format: format.combine(
format.colorize({all: true}),
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
format.printf((info) => `${info.timestamp} [${info.level}]: ${info.message}`),
)
}));
}
// Initialize Sequelize
const db = new Sequelize({
@@ -23,4 +40,4 @@ async function testConnection() {
}
// Export Sequelize instance and models
export { db, testConnection };
export { logger, db, testConnection };