@sign-logger/express
@sign-logger/core & on-finished
Dependencies:Usage
import { ExpressJS } from '@sign-logger/express';
import express from 'express';
const app = express();
app.use(ExpressJS('dev')); // Available levels: 'dev', 'compact', 'production'
app.get("/", (req, res) => {
res.send('Hello World!');
});
app.listen(8080)
Custom Logger
register
method to decorators
Todo: Change from the Custom loggers can easily be created by extending the Base
class
import { Base, HttpGroups, useCustomLogger } from '@sign-logger/express';
import { format, Colors, Backgrounds } from '@sign-logger/core';
import express, { Request, Response } from 'express';
class CustomLogger extends Base {
onInformational(req: Request, res: Response) {
console.log(format(`${req.method} ${req.originalUrl} INFORMATIONAL`).apply(Colors.WHITE, Backgrounds.BLUE));
}
onAnotherInformational(req: Request, res: Response) {
console.log(format(`${req.method} ${req.originalUrl} another INFORMATIONAL`).apply(Colors.WHITE, Backgrounds.BLUE));
}
}
const app = express();
const logger = new CustomLogger();
logger.register(HttpGroups.INFORMATIONAL, logger.onInformational, onAnotherInformational);
app.use(useCustomLogger(logger));
Base#register(group: HttpGroups, ...methods: Function[])
Used to register listeners for a specific HTTP group
enum HttpGroups
Used to define the HTTP group for the listeners
INFORMATIONAL (100 - 199)
SUCCESS (200 - 299)
REDIRECTION (300 - 399)
CLIENT_ERROR (400 - 499)
SERVER_ERROR (500 - 599)