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

@tlscipher/holt

v1.2.0

Published

A highly configurable logger middleware for ElysiaJS.

Downloads

142

Readme

@tlscipher/holt

A highly configurable logger middleware for ElysiaJS.

Named after Raymond Holt from Brooklyn Nine-Nine

Demo Image

Installation

bun add @tlscipher/holt

Usage

import { HoltLogger } from "@tlscipher/holt";
import { Elysia } from "elysia";

new Elysia()
  .use(new HoltLogger().getLogger())
  .get("/", () => {})
  .listen(3000);

Configuration

HoltLogger

The constructor for HoltLogger function accepts an optional parameter of type HoltConfig.

interface HoltConfig {
  format: string;
  colorful: boolean;
}
  • format (Default: ":date | :method :path - :status (:request-duration ms)")

    • The format parameter allows you to customize the log output that is written to the console using tokens.
  • colorful (Default: true)

    • The colorful parameter allows to specifiy a boolean value of wether or not you would like the logger output to be color-coded based on the HTTP response status code.

Possible Tokens for Format

  • :date The time at which the response was sent.
    • Example output: 2023-09-16T21:15:04.516Z
  • :method The HTTP method that was used for the inbound request.
    • Example output: GET
  • :path The path of the inbound HTTP request
    • Example output: /health
  • :request-duration The difference in milliseconds from the time the request was received, to the time the response was sent
    • Example output: 4.28

Adding Headers to the Format

This package allows you to log any of the available incoming headers.

Format for header tokens:

  • :header[<header-key-here>]

Examples:

  • :header[user-agent]
    • Example output: PostmanRuntime/7.33.0
  • :header[accept]
    • Example output: application/json
  • :header[authorization]
    • Example output: Bearer auth_xxxxxx...

Custom Tokens

You can now add custom tokens to your logger using the HoltLogger.token function. The function accepts the following parameters:

  • token (required string)
    • The string to be tokenized and used and the replacer in the format
  • extractFn (required function)
    • The function will be given access to select properties of ELysia's context and must return the string value to replace the token in the format.

Example Custom Token Usage

import { HoltLogger } from "@tlscipher/holt";
import { Elysia } from "elysia";

new Elysia()
  .use(
    new HoltLogger({
      format: ":method :path | :is-admin",
    })
      .token("is-admin", ({ headers }) => {
        return headers["x-admin-api-key"] === "admin-api-key-here"
          ? "Admin Request"
          : "User Request";
      })
      .getLogger()
  )
  .get("/", () => {})
  .listen(3000);