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 🙏

© 2026 – Pkg Stats / Ryan Hefner

pretty-logger-js

v1.0.2

Published

Lightweight, customizable Node.js logging module with multiple transports and formatters.

Readme

pretty-logger-js

A lightweight, logging module that provides a plug-in style transmission and formatter.

Features

  • Log levels: debuginfowarnerrorsilent
  • Formatters: plain text, colorized (dev), and JSON (production)
  • Transports: Console, File (with rotation), HTTP
  • Child loggers: inherit config, add scoped metadata
  • Runtime control: change level or add/remove transports on the fly
  • No external dependencies

Quick start

const { logger } = require('./pretty-logger-js');

logger.info('Server started', { port: 3000 });
logger.warn('High memory', { mb: 512 });
logger.error('DB failed', { host: 'localhost' });

Set the minimum level via the LOG_LEVEL environment variable (default: info):

LOG_LEVEL=debug node app.js

Custom logger

const {
  Logger,
  createConsoleTransport,
  createFileTransport,
  colorFormatter,
  jsonFormatter,
} = require('./pretty-logger-js');

const logger = new Logger({
  level: 'debug',
  name:  'my-app',          // added to every log entry's meta
  transports: [
    createConsoleTransport({ formatter: colorFormatter }),
    createFileTransport({
      filePath:  './logs/app.log',
      formatter: jsonFormatter,
      maxBytes:  10 * 1024 * 1024,  // 10 MB → then rotate
      maxFiles:  5,                  // keep 5 rotated files
    }),
  ],
});

Child loggers

Inherit all settings but inject extra metadata into every entry:

// In your request middleware:
const reqLogger = logger.child({ requestId: req.id, userId: req.user.id });
reqLogger.info('Request received', { method: req.method, path: req.path });
// → meta always contains requestId and userId

HTTP transport

Send logs to an external endpoint (e.g. a log aggregator):

const { createHttpTransport } = require('./pretty-logger-js');

const logger = new Logger({
  transports: [
    createHttpTransport({
      url:     'https://logs.example.com/ingest',
      headers: { Authorization: 'Bearer MY_TOKEN' },
      levels:  ['error', 'warn'],   // only send errors and warnings
      timeout: 3000,
    }),
  ],
});

Runtime control

// Silence all logs (e.g. in tests)
logger.setLevel('silent');

// Re-enable
logger.setLevel('info');

// Add a transport after creation
logger.addTransport(createFileTransport({ filePath: './debug.log' }));

// Remove a transport by name
logger.removeTransport('file');

Formatters

| Formatter | Output | Best for | |------------------|---------------------------------------------------------------------|---------------| | colorFormatter | [timestamp] [INFO ] message {"key":"value"} (ANSI colors) | Dev console | | plainFormatter | [timestamp] [INFO ] message {"key":"value"} (no color) | File output | | jsonFormatter | {"timestamp":"...","level":"info","message":"...","meta":{...}} | Production / log aggregators |

Custom formatter

A formatter is just a function — write your own:

function myFormatter(level, message, meta) {
  return `${level.toUpperCase()} | ${message} | ${JSON.stringify(meta)}`;
}

createConsoleTransport({ formatter: myFormatter });

API reference

new Logger(options)

| Option | Type | Default | Description | |---------------|------------|-----------|------------------------------------------| | level | string | 'info' | Minimum level to emit | | transports | array | [] | Transport objects | | defaultMeta | object | {} | Merged into every log entry's meta | | name | string | — | Added as meta.logger |

logger.log(level, message, meta?)

logger.debug/info/warn/error(message, meta?)

logger.child(meta)Logger

logger.setLevel(level)

logger.addTransport(transport)

logger.removeTransport(name)


File structure

pretty-logger-js/
  index.js              ← public API + default instance
  logger.js             ← Logger class
  formatter.js          ← plain, color, JSON formatters
  transports/
    console.js          ← stdout/stderr transport
    file.js             ← file transport with rotation
    http.js             ← HTTP/HTTPS POST transport
  examples/
    basic.js            ← simple usage
    advanced.js         ← full feature demo
  README.md
  package.json

Running the examples

node examples/basic.js
node examples/advanced.js

Logs written to files will appear in ./logs/.


License

MIT