npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

borgen

v2.0.0

Published

A fully customizable HTTP request logger for node-express .

Downloads

20

Readme

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' });
});

Custom Logger 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