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

@tailwindapp/logger

v0.2.0

Published

Structured Logger for Tailwind

Downloads

39

Readme

Tailwind Logger

The purpose of the Tailwind Logger is to provide a way to create well typed, structured, consistent logs.

This will allow services like Elastic Search or Datadog to properly index all fields on the log.

Installation

npm install @tailwindapp/logger

Usage

Service Name

To use the logger, you must initialize it with a service name.

const log = new LambdaLogger({
  service: 'image-service'
});

Levels

You can also initialize it with a logging level. The default level is 'warning'.

const log = new LambdaLogger({
  service: 'image-service',
  level: 'debug'
});

If you log an error that is the same or above the initially set level, it will write the log.

If it is below the initially set level it will not write the log.

For example, if we set the level to warning:

const log = new LambdaLogger({
  service: 'image-service',
  level: 'warning'
});

log.error('Error Message') // ✔️ this will be written
log.warning('Warning Message') // ✔️ this will written
log.info('Info Message') // ❌ this will not be written
log.debug('Debug Message') // ❌ this will not be written

If we set the level to debug then all logs will be written

const log = new LambdaLogger({
  service: 'image-service',
  level: 'warning'
});

log.error('Error Message') // ✔️ this will be written
log.warning('Warning Message') // ✔️ this will written
log.info('Info Message') // ✔️ this will written
log.debug('Debug Message') // ✔️ this will written

. The valid levels in descending order of priority:

  • 'emerg'
  • 'alert'
  • 'critical'
  • 'error'
  • 'warning'
  • 'notice'
  • 'info'
  • 'debug'

See RFC 5424.

Data, Metrics & Errors

You can also pass in additional data or metrics that are relevant to the logs.

You can also pass in an error object if you are catching a thrown error somewhere.

data must be in a string: string format

metrics must be in a string: number format.

error can be any error that you catch. It will be unwrapped for you if possible

This is so they can be properly auto-indexed by Elastic Search.

const log = new LambdaLogger({
  service: 'image-service',
  level: 'warning'
});

const loginError = new Error('Malformed login request');

log.error('Login Failed!', {
  data: {
    username: 'piesupplies'
  },
  error: loginError
});

log.warning('Post rate is very high', {
  metrics: {
    posts: 50
  },
  data: {
    email: '[email protected]'
  }
});

Metrics Only

Metrics can also be logged directly, with an optional prefix.

This allows you to send metrics to ES for monitoring, no matter what the log level of the logger is set to.

Log.metrics({
  'image_saved': 5,
  'image_failed': 0
}, 'pablo');

Specific Loggers

LambdaLogger

Currently the only logger we have is the LambdaLogger.

Once we need another logger it would be good to split this into a generic log class, and specific loggers that extend it.

const log = new LambdaLogger({
  level: 'warning'
});