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

@macfja/pino-fingers-crossed

v1.1.0

Published

A pino transport hold log until a log level is reach

Downloads

15

Readme

Fingers Crossed transport for Pino

A pino transport hold log until a log level is reach.

Installation

npm install @macfja/pino-fingers-crossed

Why

In most case, you don't need logs to tell you every step and detail about your normally operating application.

But when an error occurs you want the maximum data possible.

Here enter the Fingers Crossed transport, it will hold all messages until a threshold, and there release all messages it has. So you can add all the log you want in your code, and you will have them only when needed.

Usage

To add the fingers-crossed feature to pino, you need to wrap your pino transport in the default function of the library.

[!NOTE] If you don't specify a transport, the standard output will be used.

By default, the transport will not hold any log, to activate the feature you need to add a binding, the name of the binding is the variable enable from the library, and the value is minimum log level to reach to release all the message in the queue.

[!NOTE] This added binding will not appear in your logs

Each logger (the current one or its child) will have its separated message queue, so logging a message that trigger a messages release will only be for the logger that log it, and not any of its parents. Every child can have its own message level to trigger the queue. You can even change it on the fly (note that only new log can trigger a queue release), you just have to redeclare the binding.

[!TIP] It's best suited if you create a new child logger for each business event that you receive (it can be a HTTP request, cron task, MQ message, etc.)

You can deactivate the feature by setting the trigger level to false.

If your logger have the feature activated, but you still want to log directly a message, you can pass the trigger level to false in the first parameter of the logging function (see example below)

Example

import pino from "pino"
import fingersCrossed, { enable } from "@macfja/pino-fingers-crossed"

const logger = pino(fingersCrossed());

logger.info('Will appear immedialty')
logger.error('Will appear immedialty')

logger.setBindings({ [enable]: 50 })
logger.info('Will NOT appear immedialty')
logger.info('Will NOT appear immedialty')
logger.error('Will appear immedialty as well as the 2 previous messages') // error log are level 50
logger.info('Will NOT appear')
logger.info({ [enable]: false }, 'Will appear immedialty')
logger.info('Will NOT appear')

const child = logger.child({ [enable]: 60 }, { msgPrefix: '(child) ' })
child.info('Will NOT appear immedialty')
child.error('Will NOT appear immedialty')
child.info('Will NOT appear immedialty')
child.fatal('Will appear immedialty as well as the 3 previous messages') // fatal log are level 60
child.warn('Will NOT appear')

const great_child = child.child({ [enable]: 40 }, { msgPrefix: '(great child) ' })
great_child.info('Will NOT appear immedialty')
great_child.error('Will appear immedialty as well as the previous message') // error log are level 50
great_child.warn('Will appear immedialty') // warn log are level 40
great_child.info('Will NOT appear')

Memory

The message of a Logger is keep in memory (if the [enable] binding is defined) until the trigger is reach.

But all messages are deleted from memory if the logger is freed with the Garbage Collector. For example, if you create a new logger (or child logger) inside a function, all messages not send at the end of the function will be removed (without being outputted).