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

seneca-pino-adapter

v0.1.4

Published

A Pino log adapter for the Seneca framework.

Downloads

7

Readme

Logo

A Node.js toolkit for Microservice architectures

Seneca Pino Adapter

npm version Build Status Coverage Status

A log adapter for the Seneca microservice toolkit that enables you to output your logs to Pino. The code in this project follows the Seneca custom logger example.

https://github.com/senecajs/seneca/blob/master/docs/examples/custom-logger.js

Why?

I have been working with Seneca for a short period of time and while I found the toolkit very useful though I was very frustrated by the lack of ability to manage and control my log output. I found a few examples that enabled external loggers such as Pino and I am hopeful this adapter along with other Pino add-ons will satisfy my requirements.

Pino - Super Fast, All Natural JSON Logger

Pino claims to be an extremely fast Node.js logger, inspired by Bunyan. View additional details at the following url.

https://github.com/pinojs/pino

Install

$ npm install --save seneca-pino-adapter

Usage

Configure Using an Existing Pino Logger Instance

This option will allow you complete control over creating a pino logger instance.

// Seneca support.
const Seneca = require('seneca')

// Pino Support.
const Pino = require('pino')

// Load the adapter.
const PinoLogAdapter = require('seneca-pino-adapter')

// Create a pino logger instance.
const logger = Pino({level: 'info'})

// Initialize the Seneca toolkit with the PinoLogAdapter and a Pino instance.
const seneca = Seneca({
  internal: {
    logger: new PinoLogAdapter({
      logger: logger
    })
  }
})

// Log output via Seneca.
seneca.log.debug('This is a debug log statement!')
seneca.log.info('This is an info log statement!')
seneca.log.error('This is an error log statement!')
seneca.log.warn('This is a warn log statement!')
seneca.log.fatal('This is a fatal log statement!')

Configure Using a Pino Logger Configuration

// Seneca support.
const Seneca = require('seneca')

// Load the adapter.
const PinoLogAdapter = require('seneca-pino-adapter')

// Create a pino logger instance using configuration.
const config = {level: 'info'}

// Initialize the Seneca toolkit with the PinoLogAdapter and a Pino configuration object.
const seneca = Seneca({
  internal: {
    logger: new PinoLogAdapter({
      config: {
        level: 'info'
      }
    })
  }
})

// Log output via Seneca.
seneca.log.debug('This is a debug log statement!')
seneca.log.info('This is an info log statement!')
seneca.log.error('This is an error log statement!')
seneca.log.warn('This is a warn log statement!')
seneca.log.fatal('This is a fatal log statement!')

or

// Initialize the Seneca toolkit with the PinoLogAdapter and a Pino configuration object and a output stream.
const seneca = Seneca({
  internal: {
    logger: new PinoLogAdapter({
      config: {
        level: 'info'
      },
      stream: output_stream
    })
  }
})

// Log output via Seneca.
seneca.log.debug('This is a debug log statement!')
seneca.log.info('This is an info log statement!')
seneca.log.error('This is an error log statement!')
seneca.log.warn('This is a warn log statement!')
seneca.log.fatal('This is a fatal log statement!')

Caveats

  • Custom log levels are not supported at the current time.

Inspired by Seneca Pino Logger

I tried using the Seneca Pino Logger in an attempt to have Seneca logging that was fast, configurable levels, easy filtering of content at a detailed level, etc. I found that at this time all of the features I needed were not supported so I submitted a pull request. After studying the issues a bit I was inspired to create a new Pino adapter that could be utilized right now. I took a slightly different approach than the original project so I am not sure if my changes are compatible. Possibly if the approach in this project is useful then the code can be merged back at some point. In the mean time I am publishing this project to NPM so it can be easily accessed.

For details on the Seneca plugin go here:

https://github.com/senecajs/seneca-pino-logger