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 🙏

© 2024 – Pkg Stats / Ryan Hefner

lt_log

v0.1.0

Published

`< log` is a versatile logging library for TypeScript designed to support both **JSON** and **plain-text** logging formats. It provides colorized output in plain-text mode and supports structured logs in JSON format with contextual data.

Downloads

79

Readme

< log - A Flexible and Powerful Logger for TypeScript

< log is a versatile logging library for TypeScript designed to support both JSON and plain-text logging formats. It provides colorized output in plain-text mode and supports structured logs in JSON format with contextual data.

Features

  • Supports two modes: JSON and plain-text
  • Colorized logs for different log levels in plain-text mode
  • Structured logging with context fields in JSON mode
  • Configurable log levels: debug, info, warn, error, fatal
  • Easy to integrate and lightweight

Installation

You can install the library using npm or Yarn:

npm install log

or

yarn add log

Usage

1. Basic Setup:

Here is a basic example of how to use < log:

import Logger, { LogLevel, LogMode } from '<log>';

// Create a logger with JSON output
const jsonLogger = new Logger(LogLevel.Info, LogMode.Json);
jsonLogger.info('User login successful', { userId: 123 });

// Create a logger with colored plain-text output
const plainLogger = new Logger(LogLevel.Info, LogMode.Plain);
plainLogger.info('User logged out', { userId: 456 });

2. Log Levels:

< log supports five log levels, which can be used to filter logs based on severity:

  • debug: Detailed information typically useful only during development.
  • info: General information about app behavior.
  • warn: An indication that something unexpected happened, but the app is still functioning.
  • error: A problem that requires attention.
  • fatal: A critical problem that will cause the app to stop functioning.

Example:

plainLogger.debug('This is a debug message');
plainLogger.info('This is an info message');
plainLogger.warn('This is a warning');
plainLogger.error('An error occurred');
plainLogger.fatal('A fatal error occurred');

3. Contextual Logging

You can add contextual data to your logs, which will appear as structured fields in JSON mode and as key-value pairs in plain-text mode.

jsonLogger.info('Fetching user details', { userId: 789, action: 'fetch' });
plainLogger.error('Failed to fetch user details', { userId: 789, errorCode: 500 });

JSON Output Example:

{
  "timestamp": "2024-09-21T12:00:00.000Z",
  "level": "info",
  "message": "Fetching user details",
  "context": {
    "userId": 789,
    "action": "fetch"
  }
}

Plain-text Output Example:

[2024-09-21T12:00:00.000Z] [INFO] Fetching user details | userId: 789, action: fetch

4. Configuration:

  • Log Levels:
    The log level can be configured when creating a Logger instance. Logs below the specified level will be ignored.
const logger = new Logger(LogLevel.Warn, LogMode.Plain);
// This will not log since it's below the Warn level
logger.info('This will not be logged');
  • Log Modes:
    < log supports two log modes:
  1. JSON: Structured logging, with each message and context serialized as JSON.
  2. Plain-text: Colorized logs with key-value pairs for context.
const logger = new Logger(LogLevel.Info, LogMode.Json);

5. Colored Output for Plain-text

Log levels are colorized for easier reading in plain-text mode:

  • debug: Magenta
  • info: Blue
  • warn: Yellow
  • error: Red
  • fatal: White text on a red background