@sign-logger/express
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@sign-logger/express

Dependencies: @sign-logger/core & on-finished

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

Todo: Change from the register method to decorators

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)

Authors

Collbrothers

Package Sidebar

Install

npm i @sign-logger/express

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

15.3 kB

Total Files

11

Last publish

Collaborators

  • collbrothers