Built custom log format

This commit is contained in:
2025-12-17 09:35:12 -05:00
parent 9953e2765a
commit 637968552d
3 changed files with 34 additions and 2 deletions

View File

@@ -5,8 +5,26 @@ import express = require('express');
import cors = require('cors');
import morgan = require('morgan');
const app = express()
app.use(morgan('dev', {
skip: (req) => {
import chalk from 'chalk';
app.use(morgan((tokens: morgan.TokenIndexer, req: express.Request, res: express.Response) => {
const status = Number(tokens.status(req, res));
// Colorize status code
const statusColor = status >= 500 ? chalk.red
: status >= 400 ? chalk.yellow
: status >= 300 ? chalk.cyan
: chalk.green;
return [
chalk.gray(`[${new Date().toISOString()}]`),
chalk.blue.bold(tokens.method(req, res)),
tokens.url(req, res),
statusColor(status),
chalk.magenta(tokens['response-time'](req, res) + ' ms'),
chalk.yellow(`- User: ${req.user?.name ? `${req.user.name} (${req.user.id})` : 'Unauthenticated'}`),
].join(' ');
}, {
skip: (req: express.Request) => {
return req.originalUrl === '/members/me';
}
}))