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

@usageflow/logger

v0.1.1

Published

UsageFlow logger with pino and silent mode support

Readme

@usageflow/logger

UsageFlow logger with pino and silent mode support.

Installation

npm install @usageflow/logger

Usage

Basic Usage

import { usLogger } from '@usageflow/logger';

const logger = usLogger();
logger.info('Hello, world!');
logger.error('An error occurred');

Note: By default, logs are formatted with colors for better readability. You can disable this by setting pretty: false.

Initialize with Service Name

You can initialize the logger with a service name that will be automatically included in all logs:

import { usLogger } from '@usageflow/logger';

// Pass service name in the config object
const logger = usLogger({ service: 'USAGEFLOW_BASE' });
logger.info('Service started');
// Logs will include: { service: 'USAGEFLOW_BASE', msg: 'Service started' }

// With additional options
const logger2 = usLogger({
  service: 'MY_SERVICE',
  silent: false,
});
logger2.info('Another service');
// Logs will include: { service: 'MY_SERVICE', msg: 'Another service' }

Silent Mode

When silent: true is set, the logger will not output any logs:

import { usLogger } from '@usageflow/logger';

const logger = usLogger({ silent: true });
logger.info('This will not be printed');
logger.error('This will not be printed either');

Colored Logs (Pretty Printing)

By default, the logger uses pino-pretty to format logs with colors for better readability. You can control this behavior:

import { usLogger } from '@usageflow/logger';

// Default: colored, formatted logs
const logger = usLogger({ service: 'MY_SERVICE' });
logger.info('This will be colored and formatted');

// Disable pretty printing (use raw JSON logs)
const logger2 = usLogger({
  service: 'MY_SERVICE',
  pretty: false,
});
logger2.info('This will be raw JSON');

With Pino Options

You can pass pino configuration options. Note: if pretty: true (default), the transport option will be used for pretty printing:

import { usLogger } from '@usageflow/logger';

const logger = usLogger({
  service: 'MY_SERVICE',
  silent: false,
  pretty: false, // Disable pretty to use custom pino options
  pinoOptions: {
    level: 'debug',
  },
});

logger.debug('Debug message');

Context Support

You can set context that will be included in all log messages:

import { usLogger } from '@usageflow/logger';

const logger = usLogger();

// Set context that will be included in all logs
logger.setContext({
  component: 'api',
  requestId: 'req-123',
  userId: 'user-456',
});

logger.info('Processing request');
// Logs will include: { component: 'api', requestId: 'req-123', userId: 'user-456', msg: 'Processing request' }

// Update context
logger.setContext({ requestId: 'req-789' }); // Merges with existing context

// Get current context
const context = logger.getContext();

// Remove a specific context key
logger.removeContext('userId');

// Clear all context
logger.clearContext();

Available Methods

  • log(message, ...args) - Logs an info message
  • info(message, ...args) - Logs an info message
  • warn(message, ...args) - Logs a warning message
  • error(message, ...args) - Logs an error message
  • debug(message, ...args) - Logs a debug message
  • trace(message, ...args) - Logs a trace message
  • fatal(message, ...args) - Logs a fatal message
  • child(bindings) - Creates a child logger with additional bindings
  • setSilent(silent) - Sets the silent mode
  • isSilent() - Returns whether the logger is in silent mode
  • setContext(context) - Set context that will be included in all log messages
  • getContext() - Get current context
  • clearContext() - Clear all context
  • removeContext(key) - Remove a specific context key

Example

import { usLogger } from '@usageflow/logger';

const logger = usLogger({ silent: false });

logger.info('Application started');
logger.warn('This is a warning');
logger.error('This is an error');

// Create a child logger
const childLogger = logger.child({ component: 'api' });
childLogger.info('API request received');

// Toggle silent mode
logger.setSilent(true);
logger.info('This will not be logged');

logger.setSilent(false);
logger.info('This will be logged again');