• Stars
    star
    147
  • Rank 251,347 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐ŸŒฒhigh performance debug logging ๐Ÿž

pino-debug stability

npm version build status test coverage downloads dependencies freshness js-standard-style

High performance debug logging.

Seamlessly integrates the debug module with the high performance pino logger so you can turn on debug logs in production scenarios with minimum overhead.

  • Up to 10x faster than using debug (20x in extreme mode!)
  • JSON output with more detail (pino/bunyan/bole format)
  • Safe with circular references (debug isn't)
  • No need to replace any debug logging calls
  • Associate namespaces with log levels
  • Compatible with the entire pino ecosystem

Installation

$ npm install --save pino-debug

Usage

Preload

If all you want is fast JSON logging to STDOUT

$ DEBUG=* node -r pino-debug app.js

Namespaces are enabled the usual way, via the DEBUG environment variable.

The namespace is also included in the log output, in the ns key.

Here's a sample log when the above is applied to a generic express app:

{"pid":8784,"hostname":"Davids-MacBook-Pro.local","level":20,"time":1480277659273,"msg":"skip empty body","ns":"body-parser:json","v":1}

Programmatic

For fine grained control over output stream, and mappings between debug namespaces and pino logger levels, supply a pino instance and an optional options object with a map property containing mappings.

NOTE: pino-debug must be required at the entry point of your node process, before any other modules have been loaded

Again this example assumes a generic express app:

const pinoDebug = require('pino-debug')
const logger = require('pino')({level: process.env.LEVEL || 'info'}, process.stderr);
pinoDebug(logger, {
  auto: true, // default
  map: {
    'example:server': 'info',
    'express:router': 'debug',
    '*': 'trace' // everything else - trace
  }
})

The auto option turns on any namespaces listed in the map object (so we don't have to use the DEBUG environment variable to turn them on).

API

NOTE: pino-debug can only be called once.

pinoDebug(pinoInstance) => undefined

Call pino-debug with a pino logger instance only and any debug namespaces enabled via DEBUG or debug.enable will be logged with the level 20 ('debug').

Remember, if you want to see the messages you need to set the pino logger instance logging level to 'debug'.

pinoDebug() => undefined

Call pino-debug without arguments and a default pino instance will be created with the logging level set to 20 ('debug' level).

Any debug namespaces enabled via DEBUG or debug.enable will be logged with the level 20 ('debug').

pinoDebug(pinoInstance, opts) => undefined

This is the recommended usage. Call pino-debug with a pino logger instance, and an opts object containining map property.

opts.map {'debug-namespace: 'pino-loglevel-label'}

The keys of the map property correspond to the same namespaces that can be set on the DEBUG environment variable:

pinoDebug(pinoInstance, {
  map: {
    'my-app': 'info',
    'some-dep:*': 'debug',
    '*': 'trace'
  }
})

opts.auto [true] | false

If true (default) any debug namespaces found in the keys of opts.map will be enabled.

Additionally, any debug namespaces enabled via DEBUG or debug.enable will be logged with the level 20 ('debug').

If false, any namespaces that appear in opts.map and are enabled via DEBUG or debug.enable will be logged to with the corresponding log level, (as specified in the opts.map). Any not specified in opts.map, but which are enabled via DEBUG or debug.enable will be logged with the level 20 ('debug').

opts.skip Array

Equivalent of prefixing a namespace with dash (-) when specifying DEBUG namespaces. Any namespaces specified will not be logged.

Benchmarks

$ npm run bench
==========
basic averages
Pino average: 249
Debug average: 395
PinoDebug average: 244
PinoExtremeDebug average: 119
==========
==========
object averages
PinoObj average: 262
DebugObj average: 2448
PinoDebugObj average: 256
PinoExtremeDebugDeepObj average: 126
==========
==========
deepobject averages
PinoDeepObj average: 4809
DebugDeepObj average: 30083
PinoDebugDeepObj average: 4793
PinoExtremeDebugDeepObj average: 4810
==========

Example Folder

The example folder has a generic express app, with some additions.

The package.json file has the following scripts:

  "start": "node ./bin/www",
  "start-preload": "DEBUG=* node -r ../ ./bin/www",
  "start-programmatic": "./bin/www-programmatic",
  "start-programmatic-debug": "LEVEL=debug ./bin/www-programmatic",
  "start-programmatic-trace": "LEVEL=trace ./bin/www-programmatic"

The start-preload script demonstrates preload usage. It set's the DEBUG environment variable to log everything, and then uses the -r flag to load pino-debug (relatively referenced).

The three scripts beginning start-programmatic all use a different entry point where pino-debug has been required and instantiatd with a pino instance and the mappings (as shown in usage examples).

License

MIT

Acknowledgements

Sponsored by nearForm

More Repositories

1

pino

๐ŸŒฒ super fast, all natural json logger
JavaScript
14,160
star
2

pino-pretty

๐ŸŒฒBasic prettifier for Pino log lines
JavaScript
1,212
star
3

pino-http

๐ŸŒฒ high-speed HTTP logger for Node.js
JavaScript
535
star
4

sonic-boom

Extremely fast utf8 only stream implementation
JavaScript
266
star
5

thread-stream

A streaming way to send data to a Node.js Worker Thread
JavaScript
229
star
6

express-pino-logger

๐ŸŒฒ an express middleware to log with pino
JavaScript
199
star
7

pino-elasticsearch

๐ŸŒฒ load pino logs into Elasticsearch
JavaScript
176
star
8

koa-pino-logger

๐ŸŒฒ pino logging koa middleware
JavaScript
91
star
9

pino-tee

๐ŸŒฒ tee pino logs into a file, with multiple levels
JavaScript
89
star
10

pino-multi-stream

๐ŸŒฒ A wrapper for Pino to provide Bunyan's multiple stream API
JavaScript
69
star
11

pino-nextjs-example

JavaScript
66
star
12

pino-noir

๐ŸŒฒ pino log redaction ๐Ÿท
JavaScript
66
star
13

pino-std-serializers

๐ŸŒฒ A list of standard object serializers for the Pino logger
JavaScript
58
star
14

pino-caller

๐ŸŒฒ Include call site of pino log messages
JavaScript
56
star
15

pino-mongodb

๐ŸŒฒ Insert JSON from stdin into MongoDB
JavaScript
54
star
16

pino-socket

๐ŸŒฒ A transport for sending pino logs to network sockets
JavaScript
42
star
17

pino-abstract-transport

Write Pino transports easily
JavaScript
34
star
18

pino-syslog

๐ŸŒฒ A transport for reformatting pino logs into standard syslog format
JavaScript
29
star
19

pino-arborsculpture

๐ŸŒฒ Change Pino log levels in a running process
JavaScript
24
star
20

pino-opentelemetry-transport

OpenTelemetry transport for Pino
JavaScript
21
star
21

pino-webpack-plugin

JavaScript
19
star
22

quick-format-unescaped

Solves a problem with util.format
JavaScript
17
star
23

pino-gelf

๐ŸŒฒ Convert Pino logs to GELF format and send to Graylog
JavaScript
13
star
24

restify-pino-logger

๐ŸŒฒ pino logging restify middleware
JavaScript
12
star
25

pino-inspector

Send your pino logs to the node inspector!
JavaScript
12
star
26

pino-http-print

๐ŸŒฒ debug HTTP printer for pino
JavaScript
9
star
27

pino-filter

๐ŸŒฒ A transport to filter log lines in the manner of the `debug` module
JavaScript
9
star
28

real-require

Keep require and import consistent after bundling or transpiling.
JavaScript
8
star
29

pino-clf

๐ŸŒฒ Transport which transforms Pino HTTP logs into Common Log Format
JavaScript
5
star
30

getpino.io

The website for pino
CSS
5
star
31

pino-toke

๐ŸŒฒ Transform Pino HTTP log messages with a format string
JavaScript
5
star
32

pino-test

JavaScript
2
star
33

pino-sapling

๐ŸŒฒ seed template for creating pino plugins/libraries/transports/utilities/modules
JavaScript
2
star
34

community

๐ŸŒฒ data on the members of the pino community
JavaScript
1
star
35

rill-pino-logger

๐ŸŒฒpino logging rill middleware
JavaScript
1
star