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

ssslogger

v3.1.0

Published

A super simple structured JSON logger for Node.js and other platforms

Readme

ssslogger

A super simple structured JSON logger for Node.js with TypeScript support.

Features

  • 🚀 Lightweight: Minimal dependencies, fast performance
  • 📝 Structured JSON: All logs are formatted as JSON for easy parsing
  • 🔧 Configurable: Set log levels, logger names, and custom hooks
  • 🛡️ TypeScript: Full TypeScript support with type definitions
  • 🔄 Error Handling: Graceful handling of circular references and errors
  • Zero Config: Works out of the box with sensible defaults

Installation

npm install ssslogger

Quick Start

import { log } from "ssslogger";

// Simple logging
log.info("server_started");
log.warn("high_memory_usage_detected");
log.error("database_connection_failed");

// Logging with additional data
log.info("user_logged_in", { userId: 123, ip: "192.168.1.1" });
log.error("api_request_failed", {
  endpoint: "/api/users",
  statusCode: 500,
  error: new Error("Internal server error"),
});

API

Default Logger

The package exports a default logger instance:

import { log } from 'ssslogger';

log.debug(message, obj?);
log.info(message, obj?);
log.warn(message, obj?);
log.error(message, obj?);

Custom Logger

Create a custom logger with specific configuration:

import { createLogger } from "ssslogger";

const logger = createLogger({
  logger: "my-app", // Logger name for identification
  level: "info", // Only log info, warn, and error
  hooks: [customHook], // Custom logging hooks
});

Configuration Options

interface LoggerConfig {
  logger: string; // Logger name (required)
  level?: "debug" | "info" | "warn" | "error"; // Default: 'debug'
  hooks?: LogHook[]; // Default: [consoleHook]
}

Available Exports

import { 
  createLogger, 
  consoleHook, 
  type LogLevel, 
  type LogHook, 
  type LogHookArgs,
  type Log 
} from "ssslogger";
  • createLogger: Function to create custom loggers
  • consoleHook: Default console logging hook
  • LogLevel: Type for log levels ('debug' | 'info' | 'warn' | 'error')
  • LogHook: Type for custom logging hooks
  • LogHookArgs: Type for hook arguments
  • Log: Type for logger instances

Custom Hooks

Create custom logging hooks for advanced use cases:

import { createLogger, type LogHook } from "ssslogger";

const fileHook: LogHook = (args) => {
  // Write to file, send to external service, etc.
  fs.appendFileSync("app.log", args.formatted + "\n");
};

const logger = createLogger({
  logger: "file-logger",
  hooks: [fileHook],
});

Log Format

All logs are structured JSON with the following format:

{
  "logger": "my-app",
  "ts": "2024-03-25T12:00:00.000Z",
  "msg": "user_logged_in",
  "obj": {
    "userId": 123,
    "ip": "192.168.1.1"
  }
}

Examples

Basic Usage

import { log } from "ssslogger";

// Application startup
log.info("application_starting", {
  version: "1.0.0",
  environment: "production",
});

// Request logging
log.info("http_request", {
  method: "GET",
  url: "/api/users",
  duration: 150,
});

// Error logging
try {
  // Some operation
} catch (error) {
  log.error("operation_failed", {
    operation: "user.create",
    error: error,
  });
}

Custom Logger with Different Names and Levels

import { createLogger } from "ssslogger";

// Production logger - only warnings and errors
const prodLogger = createLogger({ 
  logger: "prod-app",
  level: "warn" 
});

// Development logger - all levels
const devLogger = createLogger({ 
  logger: "dev-app",
  level: "debug" 
});

// Database logger
const dbLogger = createLogger({ 
  logger: "database",
  level: "info" 
});

// Use appropriate logger based on environment
const logger = process.env.NODE_ENV === "production" ? prodLogger : devLogger;

Custom Hooks for External Services

import { createLogger, type LogHook } from "ssslogger";

// Send errors to external monitoring service
const monitoringHook: LogHook = (args) => {
  if (args.level === "error") {
    // Send to Sentry, DataDog, etc.
    externalService.captureException(args.obj?.error);
  }
};

// Write all logs to file
const fileHook: LogHook = (args) => {
  fs.appendFileSync("app.log", args.formatted + "\n");
};

const logger = createLogger({
  logger: "monitored-app",
  hooks: [monitoringHook, fileHook],
});

Multiple Named Loggers

import { createLogger } from "ssslogger";

// Create loggers for different parts of your application
const apiLogger = createLogger({ logger: "api" });
const dbLogger = createLogger({ logger: "database" });
const authLogger = createLogger({ logger: "auth" });

// Use them in different modules
apiLogger.info("request_received", { method: "POST", path: "/users" });
dbLogger.debug("query_executed", { sql: "SELECT * FROM users" });
authLogger.warn("invalid_token", { userId: 123 });

Error Handling

The logger handles various edge cases gracefully:

  • Circular References: Automatically detected and handled
  • Error Objects: Properly serialized with stack traces
  • Hook Failures: Isolated so one failing hook doesn't break others
  • Logger Errors: Graceful fallback with error reporting

Performance

  • Minimal overhead with efficient JSON serialization
  • Configurable log levels to reduce output in production
  • Lazy evaluation of log objects (only serialized if level is enabled)

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.