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

@uswitch/koa-signal

v1.10.11

Published

๐Ÿšฆ Hackable and configurable output rendering for loggers

Downloads

6,515

Readme

Contributors License type language test style

Overview

This package is a library inspired by Signale, to provide customisable and consistent logging for Node* services.

It tries to address the following;

  • ๐Ÿฝ Comletely Customisable - Control everything with a single JSON file
  • ๐Ÿ“ Extensible - Add your own signals and components

This allows you to create consistent logs decoupled from the actual implementation of your code.


Usage

koa-signal was designed to work seamlessly with @uswitch/koa-access & @uswitch/koa-tracer. If you use either of these, you can just plug it in like so;

import Koa from 'koa'

import Signal from '@uswitch/koa-signal'
import access, { eventAccess } from '@uswitch/koa-access'
import tracer, { eventTrace, eventError } from '@uswitch/koa-tracer'

const app = new Koa()
const signal = Signal({ /* Config overrides */ })

app.use(tracer())
app.use(access())

app.on(eventAccess, signal.access)
app.on(eventTrace, ({ ctx,key,trace }) => signal.trace({ ...ctx, ...trace, scope: key }))
app.on(eventError, ({ ctx, error }) => signal.error(ctx, error.original))


app.listen(3000, () => signal.start(Listening on port 3000))

However, you can use it entirely independently of these two libraries as a log formatter. Creating an instance of koa-signal will provide you with a bunch of different logging functions, e.g.

import Signal from '@uswitch/koa-signal'
const signal = Signal({ /* config overrides */ })

signal.info('My really useful info message')

Production vs Development

koa-signal's formatting is useful for logging in Development to give a good understanding of what's happening in your application, however, in Production you probably want your output to be machine readable.

To change the formatting for Production, you can just provide a new config file, e.g.

import Signal from '@uswitch/koa-signal'
const signal = Signal({
  levels: {
    info: { format: [] },
    trace: { format: [] },
    warn: { format: [] },
    error: { format: [] },
    access: { format: [ 'json' ] }
  },
  components: {
    json: { properties: [ 'id', 'errors', 'errorsCount', 'traces' ] }
  }
})

In Production it's a common practice to save the logs to a file as well. koa-signal supports both console and file outputs which can be used independently or together e.g.

outputs

import Signal from '@uswitch/koa-signal'
const signal = Signal({
  levels: {
    info: { format: [] },
    trace: { format: [] },
    warn: { format: [] },
    error: { format: [] },
    access: { format: [ 'json' ] }
  },
  components: {
    json: { properties: [ 'id', 'errors', 'errorsCount', 'traces' ] }
  },
  outputs: [
    { type: 'console' },
    { type: 'file', file: './path/to/file.json' }
  ]
})

API

Each Signal function is defined with a format property (See configuration) which dictates how the log output is built. For example, let's take the trace function with the following output;

๐Ÿคฆ Doh!   [9ee...498] | +2546ms | |  +123ms | [SCOPE] >  First scoped traced message

The whole output is a LEVEL, but is made up of multiple COMPONENTS;

                                  TRACE LEVEL FUNCTION
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
๐Ÿคฆ Doh!   [9ee...498] | +2546ms | |  +123ms | [SCOPE] >  First scoped traced message
โ•ฐโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ•ฏ โ•ฐโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ•ฏ โ•ฐโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ•ฏ โ•ฐโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ•ฏ โ•ฐโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ•ฏโ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
COMPONENT  COMPONENT   COMPONENT   COMPONENT   COMPONENT           COMPONENT

This is defined in config as the following;

{
  "levels": {
    "trace": {
      "badge": "๐Ÿคฆ",
      "label": "Doh!",
      "format": [ "level", "id", "time-diff-init", "time-diff-scope", "scope", "message" ]
    }
  }
}

Where [ "level", ..., "message" ] is the list of Components being used. Components also have their own configuration defined separately.

API Functions

These functions are available by default and require the following properties when called.

| Function | API | |-----------|-------------------------------------------------------------------------------------------------| | success | ({ state: { id: STRING }, msg: STRING }) | | info | ({ state: { id: STRING }, msg: STRING }) | | warn | ({ state: { id: STRING }, msg: STRING }) | | access | ({ state: { id: STRING }, req: OBJECT, res: OBJECT }, extras: OBJECT) | | trace | ({ state: { id: STRING }, initDiff: INT, timeDiff: INT, scope: STRING, msg: STRING }) | | zipkin | ({ kind: CLIENT/SERVER, state: { parent: STRING, trace: STRING }, req: OBJECT, res: OBJECT }) | | error | ({ state: { id: STRING }, msg: STRING }, ERROR) | | start | ({ msg: SRTING }) | | end | ({ msg: STRING }) |

Configuration

You can see the default configuration of koa-signal here

Contributors

Thanks goes to these wonderful people (emoji key):

| Dom Charlesworth๐Ÿ“– ๐Ÿ’ป ๐Ÿค” ๐Ÿ”Œ | David Annez๐Ÿ’ป ๐Ÿค” ๐Ÿ”Œ | | :---: | :---: |

This project follows the all-contributors specification. Contributions of any kind welcome!