Borgen

Borgen🏅 (The developers👨‍💻 logger)

NPM Version NPM Downloads Coverage Status

The custom Logger for your Node-Express app.

A HTTP request logger middleware for nodeJs

borgen logger




Installation🏗️

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm i borgen

If you use yarn:

$ yarn add borgen

If you use pnpm:

$ pnpm add borgen




🚀Usage

const { Logger, Borgen } = require('borgen');
import { Logger,Borgen } from 'borgen';

Basic use

This is the simplest way you can use Borgen, you can however customize
the colors it uses in logging.

const express = require('express');
const { Logger, Borgen } = require('borgen');

const app = express();
app.use(Borgen({}))

Logger.info({message: 'This is an informational message.'});
Logger.warn({message:'This is a warning message.'});
Logger.error({message:'This is an error message.'})

app.listen('3002', () => {
    Logger.info({ message: 'The server is running on port 3002'});
});

borgen basic use

Available Customizations: 🌞Colors




Logger💬


Basic usage

Logger.info({message: 'This is an informational message.'});
Logger.warn({message:'This is a warning message.'});
Logger.error({message:'This is an error message.'})

Logger basic use

Customizing the Colors🧰

You can fully customize the color for your log.

Logger has three options:

Each Logger option has defaults and will fallback if no arguments are passed

const express = require('express');
const { Logger, Borgen } = require('borgen');

const app = express();

app.get('/test', (req, res) => {
    Logger.warn({ message: 'This is an warning', infoColor: 'yellow', messageColor: 'yellowBright' });
    res.send('Hello world').end();
});

app.get('*', (req, res) => {
    Logger.error({ message: 'This route does not exist', infoColor: 'red', messageColor: 'redBright' });
    res.send('404 not found');
});

app.listen('3001', () => {
   Logger.info({ message: 'The server is running on port 3001', infoColor: 'cyanBright', messageColor: 'whiteBright' });
});

Logger custom use

Logger arguments💥


Note: infoColor and messageColor are optional and if not passed the logger will
will use the fallback configuration.


Use CTRL + space or Options + space with infoColor and messageColor to get all
the colors available.




Borgen middleware

This middleware is able to handle all you incoming requests and you can
customize the colors they are logged in.

Basic use

app.use(Borgen({}))

Borgen basic use

🧰Customizing the Colors

You can fully customize the color for your incoming requests.

const express = require('express');
const { Logger, Borgen } = require('borgen');

const app = express();
app.use(
    Borgen({
        methodColor: {
            GET: 'greenBright',
            POST: 'yellow',
            PUT: 'gray',
            PATCH: 'gray',
            DELETE: 'redBright'
        },
        routeColor: 'gray',
        statusColor: 'cyan',
        resTimeColor: 'gray',
        statusCodesCl: { serverErr: 'red', clientErr: 'yellow', redirects: 'cyan', success: 'greenBright' }
    })
);

app.listen('3001', () => {
   Logger.info({ message: 'The server is running on port 3001', infoColor: 'cyanBright', messageColor: 'whiteBright' });
});

Borgen custom use

Borgen arguments💥

Note: All this arguments are optional and if not passed the logger will
will use the fallback configuration.


Save my logs🚀

Using this feature you can store you apps log in a file.
This feature is useful for debugging and for production.


📑Borgen logs 🐾

logs argument allows you to specify a path where your log file will be located.

app.use(
    Borgen({
        logs: '../logs/borgen.log'
    })
);

📑Logger logs 🐾

To save your logs you need to add the logs parameter as an argument.

 Logger.info({ logs: '../logs/info.log' });
 Logger.warn({ logs: '../logs/warnings.log' });
 Logger.error({ logs: '../logs/error.log' });


Note: The 🔖log file name can be any custom name. ‘ ./custom_name.log ‘ ___



💪🏽 Thanks to all the awesome Contributors

Thanks a lot for spending your time helping Borgen grow. Thanks a lot! Keep rocking🍻

Contributors




License📑

MIT