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

@ashcorr/loglevel-colored-level-prefix

v1.0.0

Published

loglevel plugin that adds colored level prefix (node only)

Downloads

4

Readme

loglevel-colored-level-prefix

Forked from https://github.com/kentcdodds/loglevel-colored-level-prefix

loglevel plugin that adds colored level prefix (node only)

Build Status version downloads MIT License

All Contributors PRs Welcome Code of Conduct

Watch on GitHub Star on GitHub

The problem

loglevel is great, and I find that I often want the log output to be formatted the same way every time. Also I don't really like some of the implementation of loglevel (specifically the fact that it uses some browser APIs for some things.

This solution

This exposes a function to get a logger (singleton) with colored prefixes for the level. Note that this only works in Node because it uses chalk.

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's dependencies:

npm install --save loglevel-colored-level-prefix

Usage

const getLogger = require('loglevel-colored-level-prefix')
const options = {prefix: 'your-prefix', level: 'trace'}
const logger = getLogger(options)
logger.trace('WOW! What the stack trace!?')
// Trace: your-prefix [TRACE]: WOW! What the stack trace!?
//     at Logger.trace (<full-path>/node_modules/loglevel-colored-level-prefix/dist/index.js:54:24)
//     at ... etc
logger.debug('sup debug?')
// your-prefix [DEBUG]: sup debug?
logger.info('Hey info')
// your-prefix [INFO]: Hey info
logger.warn('Hi warn')
// your-prefix [WARN]: Hi warn
logger.error('Hello error')
// your-prefix [ERROR]: Hello error

Let's look at what that actually looks like...

options

prefix

?String - Whatever you want your prefix to be. Normally this is the tool that you're logging for. The getLogger function will return the same instance of the logger based on the given prefix.

level

?String - What you want the initial level to be set to. This defaults to: process.env.LOG_LEVEL || 'warn'. Possible options are (in order of verbosity): trace, debug, info, warn, error.

returns

An instance of a loglevel logger. Learn more about that API from the loglevel docs.

Inspiration

I wrote this because I wanted to use the plugin I created for prettier-eslint in prettier-eslint-cli. And I'll probably use it in other projects/tools as well.

Other Solutions

I'm unaware of other plugins for loglevel that do what this one does. But there are many logging solutions out there...

Contributors

Thanks goes to these people (emoji key):

| Kent C. Dodds💻 📖 🚇 ⚠️ | Ashleigh Carr💻 🚇 | | :---: | :---: |

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

LICENSE

MIT