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

@martinnirtl/logging

v1.0.2

Published

Preconfigured logging utility for microservices based on winston

Downloads

15

Readme

Logging Utility

Opinionated logging utility for unified logging in distributed systems based on winston.

Install

Install via npm:

npm install --save @martinnirtl/logging

Or yarn:

yarn add @martinnirtl/logging

Configuration

Programmatically configure library:

import logger, { setDefaults } from '@martinnirtl/logging'

setDefaults({
  level: 'warn',
  metadata: { service: 'foo-service' },
  prettyPrint: process.env.NODE_ENV !== 'production',
})

logger.info('hello world') // will not be printed

Or use environment variables:

# Specify log-level (default: info, options: [silly, debug, info, warn, error])
LOG_LEVEL=debug

# Add metadata tags with `LOG_METADATA_`-prefix, e.g. set { service: 'foo-service' }
LOG_METADATA_SERVICE=foo-service

# Pretty-print json-logs on truthy value (default: false)
LOG_PRETTY=true

# Silent logger on truthy value (default: false)
LOG_SILENT=0

Usage

Singleton pattern:

import logger, { setDefaults } from '@martinnirtl/logging'

setDefaults({
  level: 'debug',
  metadata: { 'process-id': process.pid },
})

logger.debug('just set the logger-defaults')

logger.info('starting application...', { date: new Date() })

Or dedicated loggers:

import { getLogger, setDefaults } from '@martinnirtl/logging'

setDefaults({
  level: 'debug',
  metadata: { service: 'foo-service' },
})

const logger = getLogger({
  metadata: { context: 'initialization' },
})

logger.info('starting application...', { date: new Date() })

Logging Middlewares

The lib also ships middlewares to optimally integrate into popular 3rd party frameworks.

At the moment, only the express framework is supported.

Express

The express middleware allows to add a logger instance to every request-handler. Also it enables logging of incoming requests plus automatic request-body|headers|query|params to logging object's metadata mapping.

const { getLogger, middleware, setDefaults } = require('@martinnirtl/logging')
const express = require('express')

setDefaults({
  level: 'debug', // default 'info'
})

const logger = getLogger({
  metadata: { context: 'init' },
})

const app = express()

app.use(middleware('express', {
  addToRequestObject: true, // default true
  logIncoming: {
    level: "debug", // default 'info'
    metadata: {
      body: true, // add body as a whole
      headers: ['host'], // add host field of headers to metadata
    }
  }
}))

app.all('/', (req, res) => {
  req.logger.debug('it works!')

  return res.status(200).send('Hello World')
})

app.listen(3000, () => logger.info(`app listening on port 3000`))