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

@niveus/winston-utils

v0.1.0

Published

Utilities, helpers, formatters, transports for winston logger.

Downloads

122

Readme

Npm package version Npm package monthly downloads GitHub issues GitHub contributors

winston-utils

Utilities, helpers, formatters, transports for winston logger.

Configs

Collection of log levels and colors. Currently supports the following ones.

  • google
  • RFC 3164

How to use config

Example usage of config.

const { google } = require('@niveus/winston-utils').config;
const winston = require('winston');
const { combine, colorize, json } = winston.format;


const logger = winston.createLogger({
    level: 'debug',
    levels: google.levels,  // Log Levels
    format: combine(
        colorize({ all: true }),
        json(),
    ),
    transports: [new winston.transports.Console()],
});

winston.addColors(google.colors);  // Log Colors

module.exports = logger;

If this is not adding the colors, try removing the colorize formatter and add it to the transports like below

// ...

transports: [new winston.transports.Console({ format: winston.format.colorize({ all: true }) })],

// ...

How To Use Logger

Each config adds its own custom log levels. Specific log levels can be called using it's corresponding method name. In the example below, it uses google config. Check the sevierity levels for the config used.

// uses google config
const logger = require('./path/to/logger');

logger.emerg('Emergency log', {custom: 'data'});
// LOG: { "level": "emerg", "message": "Emergency log", "custom": "data" }

logger.alert('Alert log', {custom: 'data'});
// LOG: { "level": "alert", "message": "Alert log", "custom": "data" }

Google Config

Log Levels

| Log Level | Severity | Description | |:---------:|:----------------------:|----------------------------------| | 0 | Emergency (emerg) | System is unusable | | 1 | Alert (alert) | Action must be taken immediately | | 2 | Critical (crit) | Critical conditions | | 3 | Error (error) | Error conditions | | 4 | Warning (warn) | Warning conditions | | 5 | Notice (notice) | Normal but significant condition | | 6 | Informational (info) | Informational messages | | 7 | Debug (debug) | Debug-level messages |

Log Colors

| Severity | Color | |:----------------------:|--------------------| | Emergency (emerg) | bold white blackBG | | Alert (alert) | bold red yelloBG | | Critical (crit) | bold white redBG | | Error (error) | black redBG | | Warning (warn) | black magentaBG | | Notice (notice) | white blueBG | | Informational (info) | white greenBG | | Debug (debug) | black yellowBG |

RFC 3164 Config

Log Levels

| Log Level | Severity | Description | |:---------:|:----------------------:|----------------------------------| | 0 | Emergency (emerg) | System is unusable | | 1 | Alert (alert) | Action must be taken immediately | | 2 | Critical (crit) | Critical conditions | | 3 | Error (error) | Error conditions | | 4 | Warning (warn) | Warning conditions | | 5 | Notice (notice) | Normal but significant condition | | 6 | Informational (info) | Informational messages | | 7 | Debug (debug) | Debug-level messages |

Log Colors

| Severity | Color | |:----------------------:|--------------------| | Emergency (emerg) | bold white blackBG | | Alert (alert) | bold red yelloBG | | Critical (crit) | bold white redBG | | Error (error) | black redBG | | Warning (warn) | black magentaBG | | Notice (notice) | white blueBG | | Informational (info) | white greenBG | | Debug (debug) | black yellowBG |

Formatters

Collection of formatters. Currently supports the following ones.

  • piiRedact

How to use piiRedact formatter

piiRedact uses fast-redact for redacting data. Kindly check the fast-redact documentation for more info.

⚠️ Use structuredClone or deep copy to log data in the log, or the redactor will mutate the data object.

Example code for using piiRedact.

// Logger file.

const { piiRedact } = require('@niveus/winston-utils').formatters;
const winston = require('winston');
const { combine, json } = winston.format;

// Configuration for the formatter.
const piiFormatterConfig = {
    paths: ['data.emailId'], // Or env based values, secrets manager, etc...
}

const piiRedactFormatter = formatters.piiRedact(piiFormatterConfig);

const logger = winston.createLogger({
    level: 'debug',
    format: combine(
        piiRedactFormatter,
        json(),
    ),
    transports: [new winston.transports.Console()],
});

module.expoers = logger;



// .... Somewhere else in the repository

const logger = require('./path/to/logger');

function resetPassword(data) {
    // data = {emailId: '[email protected]'}
    logger.debug('user password reset', {data: structuredClone(data) });

    // LOG: { "level": "debug", "message": "user password reset", "data": { "emailId": "[REDACTED]" }}

    // ... rest of the code
}

piiRedact Config

Configuration for piiRedact formatter

Example

// Default value
const config = {
    paths = [],
    censor = '[REDACTED]',
};

| Config Name | Type | Description | |:-----------:|--------|---------------------------------------------------------------------------------------------------------------------------------------| | paths | Array | Object paths to be redacted. Refer path - Array | | censor | String | The value to be replaced after redacting. Default is [REDACTED]. |