Built custom log format
This commit is contained in:
@@ -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';
|
||||
}
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user