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

@andrewheberle/ts-slog

v1.3.0

Published

Simple structured logger for TypeScript

Downloads

828

Readme

@andrewheberle/ts-slog

A simple structured logger for TypeScript applications.

Installation

npm install @andrewheberle/ts-slog

Usage

Basic Example

import { Logger } from '@andrewheberle/ts-slog'

const logger = new Logger()

logger.info("Application started")
logger.debug("Debug information", "userId", 123, "action", "login")
logger.warn("Warning message", "retries", 3)
logger.error("An error occurred", "errorCode", 500)

Log Levels

The logger supports four log levels:

  • Debug (0) - Detailed debugging information
  • Info (1) - General informational messages (default)
  • Warning (2) - Warning messages
  • Error (3) - Error messages

Configuration

Configure the minimum log level when creating a logger instance:

import { Logger, LogLevel } from "@andrewheberle/ts-slog"

// Only log warnings and errors
const logger = new Logger({ minLevel: LogLevel.Warning })

logger.debug("This won't be logged")
logger.info("This won't be logged either")
logger.warn("This will be logged")
logger.error("This will be logged too")

Adding Context

Add key-value pairs to log entries by passing additional arguments:

import { Logger } from "@andrewheberle/ts-slog"

const logger = new Logger()

logger.info(
    "User logged in",
    "userId", 123,
    "username", "john.doe",
    "ip", "192.168.1.1"
)

// Output:
// {
//   level: 'INFO',
//   message: 'User logged in',
//   userId: 123,
//   username: 'john.doe',
//   ip: '192.168.1.1'
// }

Groups

A group of K/V pairs may be grouped as follows:

import { group, Logger } from "@andrewheberle/ts-slog"

const logger = new Logger()

logger.info(
    "User logged in",
    ...group("user", "id", 123, "username", "john.doe"),
    "ip", "192.168.1.1"
)

// Output:
// {
//   level: 'INFO',
//   message: 'User logged in',
//   user.id: 123,
//   user.username: 'john.doe',
//   ip: '192.168.1.1'
// }

API

new Logger(settings?)

Creates a new logger instance.

Parameters:

  • settings (optional): Configuration object
    • logHandler: Handler to output logs (default: console.log)
    • minLevel: Minimum log level (default: LogLevel.Info)

Methods

  • debug(message: string, ...args: unknown[]): void - Log at DEBUG level
  • info(message: string, ...args: unknown[]): void - Log at INFO level
  • warn(message: string, ...args: unknown[]): void - Log at WARNING level
  • error(message: string, ...args: unknown[]): void - Log at ERROR level
  • with(...args: unknown[]): Logger - Returns a new Logger with additional K/V pairs added

Functions

  • group(key: string, ...args: unknown[]): unknown[] - Create K/V pairs based on key prefix

All methods accept a message string followed by optional key-value pairs.

License

MIT