Code Monkey home page Code Monkey logo

borgen's Introduction

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

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • blackBright (alias: gray, grey)
  • redBright
  • greenBright
  • yellowBright
  • blueBright
  • magentaBright
  • cyanBright
  • whiteBright



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:

  • Logger.info( )
  • Logger.warn( )
  • Logger.error( )

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💥

  • message This is the information you want to be logged to the console.
  • infoColor This is the color of the first section of the log.
  • messageColor This is will be the color of the message you want to log.

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💥

  • methodColor it is an Object which allows you to specify a specific color for different request types.
  • routeColor it is the color of the route of the request e.g /api/v1/users.
  • statusColor it is the color of the status text
  • resTimeColor it is the color of how long it took the request to process and give a response.
  • statusCodesCl it is where you specify the color of status codes in different ranges
    • serverErr for 5xx
    • clientErr for 4xx
    • redirects for 3xx
    • success for 2xx

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

borgen's People

Contributors

codedwells avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

borgen's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.