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

@karmaniverous/edge-logger

v1.3.12

Published

A simple logging class that renders nicely-formatted logs and plays nicely with edge networks.

Downloads

72

Readme

edge-logger

The Next.js Edge Runtime is extremely limited as to the packages it can load.

This can pose a challenge for common logging and utility packages like winston and lodash, which will fail when loaded into an edge resource.

Logging is a cross-cutting concern, and shouldn't have to care where it is executed. So this package is a simple, flexible logging utility that...

  • formats logs attractively, whether output to the console or cloud services like AWS CloudWatch.
  • features configurable logging levels (defaults to SysLog).
  • can handle virtually any input, including circular object references.
  • can truncate long strings for readability.

Installation

npm install @karmaniverous/edge-logger

Usage

import Logger from `@karmaniverous/edge-logger`;
const logger = new Logger();

logger.emerg('emergency message', { foo: 'bar' }); // rendered with console.error()
logger.alert('alert message');                     // rendered with console.error()
logger.crit('critical message');                   // rendered with console.error()
logger.error('error message');                     // rendered with console.error()
logger.warning('warning message');                 // rendered with console.warn()
logger.notice('notice message');                   // rendered with console.info()
logger.info('info message');                       // rendered with console.info()
logger.debug('debug message');                     // rendered with console.debug()
logger.log('log message');                     // rendered with console.info()

// emerg:   emergency message
// emerg:   {
// emerg:     "foo": "bar"
// emerg:   }
// alert:   alert message
// crit:    critical message
// error:   error message
// warning: warning message
// notice:  notice message
// info:    info message
// info:    log message

// debug level not rendered by default.
// Set LOG_LEVEL to 'debug' to see these.

Configuration

Set your minimum logging level with environment variable LOG_LEVEL (by default it is info).

The optional constructor config argument has the following keys:

| Key | Description | | -------------- | ------------------------------------------------------------------------------------------------------------------------ | | defaultLevel | Default logging level (invoked by the log method). Default value set in levels object (info for default levels). | | maxLevel | Maximum logging level. Default value set in levels object (info for default levels). | | levels | An alternate levels definition. See below for details. |

Levels Config

Here is the default levels object:

{
  emerg: { value: 0, console: 'error' },
  alert: { value: 1, console: 'error' },
  crit: { value: 2, console: 'error' },
  error: { value: 3, console: 'error' },
  warning: { value: 4, console: 'warn' },
  notice: { value: 5, console: 'info' },
  info: { value: 6, console: 'info', default: true, defaultMax: true },
  debug: { value: 7, console: 'debug' },
}

Each key will be rendered as a function on the Logger instance that takes a list of items, just like console.log().

The keys on each log level:

| Key | Description | | ------------ | ----------------------------------------------------- | | value | Supports setting the logging threshold. | | console | The console function invoked by the log level. | | default | true if the log method should trigger this level. | | defaultMax | true if default max level. |


See more great templates and other tools on my GitHub Profile!