Code Monkey home page Code Monkey logo

pino-context's Introduction

pino-context

A tool to give some context to your logs.

Installation

$ [sudo] npm install pino-context

Usage

Examples

Express

const express = require('express');
const pino = require('pino');
const {wrapLogger, addContext} = require('pino-context');
const expressScopeMiddleware = require('pino-context/integrations/express');
const logger = wrapLogger(pino());
const app = express();

app.use(expressScopeMiddleware());

app.use((req, res, next) => {
  addContext('requestId', 'unique identifier'); // Generate some unique identifier
  next();
});

app.use((req, res, next) => {
  logger.info('This is a log');
  next();
});

app.use((req, res, next) => {
  addContext('url', req.url);
  next();
});

app.get('/', (req, res) => {
  logger.info('This is another log');
  res.send(`Hello World`);
});

app.listen(1337, () => {
  logger.info('Listening');
});

Will output

{"level":30,"time":1551190582956,"msg":"Listening","pid":13031,"context":{},"v":1}
{"level":30,"time":1551190586342,"msg":"This is a log","pid":13031,"context":{"requestId":"unique identifier"},"v":1}
{"level":30,"time":1551190586342,"msg":"This is another log","pid":13031,"context":{"requestId":"unique identifier","url":"/"},"v":1}

Related

  • pino - A Node.js logger, inspired by Bunyan.
  • async-local-storage - The underlying library that manages the storage.

License

MIT © Omri Litov

pino-context's People

Contributors

omrilitov avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.