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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pino-console

v0.1.1

Published

WHATWG Console API adapter for Pino loggers

Readme

pino-console

A WHATWG Console API adapter for Pino loggers that provides full Node.js Console interface compatibility with structured JSON logging.

npm version License: MIT Node.js Version

Quick Start

npm install pino-console pino
import pino from 'pino'
import Console from 'pino-console'

const logger = pino()
const console = new Console(logger)

console.log('Hello, structured logging!')
// Output: {"level":30,"time":1234567890,"pid":1234,"hostname":"host","msg":"Hello, structured logging!"}

Table of Contents

Installation

npm install pino-console pino

For pretty development output:

npm install pino-pretty

Usage

Basic Setup

import pino from 'pino'
import Console from 'pino-console'

// Create a Pino logger
const logger = pino({
  level: 'info',
  transport: {
    target: 'pino-pretty' // For development
  }
})

// Create a Console adapter
const console = new Console(logger)

// Use console methods as usual
console.log('Application starting...')
console.info('This is an info message')
console.warn('This is a warning')
console.error('This is an error')

Migration from Standard Console

Replace your console usage:

// Before
console.log('User logged in:', userId)

// After
import { console } from './logger.js' // Your pino-console instance
console.log('User logged in:', userId) // Now outputs structured JSON

Log Level Control

import pino from 'pino'
import Console from 'pino-console'

// Only log warnings and errors
const logger = pino({ level: 'warn' })
const console = new Console(logger)

console.debug('Not logged')  // Filtered out
console.log('Not logged')    // Filtered out
console.warn('Logged')       // Shown
console.error('Logged')      // Shown

Level mapping:

  • console.debug()pino.debug() (level 20)
  • console.log()/info()pino.info() (level 30)
  • console.warn()pino.warn() (level 40)
  • console.error()pino.error() (level 50)

API Reference

Constructor

new Console(logger)

Creates a new Console instance.

  • Parameters: logger (Pino Logger) - A Pino logger instance
  • Throws: TypeError if logger is invalid
  • Returns: Console instance

Core Logging Methods

  • console.log(message?, ...optionalParams) - Info level logging
  • console.info(message?, ...optionalParams) - Info level logging
  • console.warn(message?, ...optionalParams) - Warn level logging
  • console.error(message?, ...optionalParams) - Error level logging
  • console.debug(message?, ...optionalParams) - Debug level logging

Format Specifiers

All logging methods support standard format specifiers:

| Specifier | Description | Example | |-----------|-------------|---------| | %s | String | console.log('Hello %s', 'world') | | %d, %i | Integer | console.log('Count: %d', 42) | | %o | Object (shallow) | console.log('Data: %o', obj) | | %O | Object (deep) | console.log('Data: %O', obj) | | %% | Literal % | console.log('100%% complete') |

Additional Methods

  • Timing: time(label?), timeEnd(label?), timeLog(label?, ...data)
  • Counting: count(label?), countReset(label?)
  • Grouping: group(...label), groupCollapsed(...label), groupEnd()
  • Display: table(tabularData, properties?), dir(obj, options?), dirxml(...data), clear()
  • Debugging: assert(value, message?, ...params), trace(message?, ...params)
  • Inspector: profile(label?), profileEnd(label?), timeStamp(label?) (no-ops)

TypeScript Support

Full TypeScript support is included:

import pino from 'pino'
import Console from 'pino-console'

const logger = pino({ level: 'info' })
export const console = new Console(logger)

// All methods are fully typed
console.log('Message with %s and %d', 'string', 42)
console.time('operation')
console.table([{ name: 'Alice' }, { name: 'Bob' }])
console.timeEnd('operation')

Examples

See example.mjs for a comprehensive demonstration of all features.

Performance

pino-console includes performance optimizations:

  • Level-enabled checks: Disabled log levels have minimal overhead
  • Lazy evaluation: Format specifiers only processed when needed
  • Structured output: Enables efficient log parsing and analysis
import pino from 'pino'
import Console from 'pino-console'

// Level filtering prevents unnecessary work
const logger = pino({ level: 'warn' })
const console = new Console(logger)

// These have near-zero cost when filtered
console.debug('Debug info', expensiveOperation()) // Skipped entirely
console.info('Info message', largeObject)         // Skipped entirely

// These are processed
console.warn('Warning')  // Processed
console.error('Error')   // Processed

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

MIT License - see LICENSE file for details.

Related