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

log-scope

v1.1.0

Published

Scoped & colorful console logging

Downloads

19

Readme

Usage

Installation

npm install log-scope

Create new log scope

import logScope from 'log-scope'
const log = logScope('scopeName')

log.success('We have a new scope!')
// scopeName [SUCCESS] (0): We have a new scope!

log.success('It has a counter per type & scope')
// scopeName [SUCCESS] (1): It has a counter per type & scope

log.debug('Use another type for debugging')
// scopeName [DEBUG] (0): Use another type for debugging

Types can be paused in a scope when you don't need e.g. debug-loggs

log.pause('debug')
log.debug('Disable logs for a type in a scope')

Create other scopes to clarify where the logs comes from in the console

// Create scopes, it's super convenient for e.g. different modules
const anotherLog = logScope('anotherScopeName')
anotherLog.success('Another scope!')
// anotherScopeName [SUCCESS] (0): Another scope!

If you only want logs from one scope, use the .only() method

// Only print from this scope
anotherLog.only()

log.info('This will not print since another log scope has the only-flag active')

Include data and other params in the logs. You can have as many parameters as you want. The types don't matter, they are printed to the console via the regular console.log-function

log.success('Logging some data', 1, 'a string', { key: 'Value' })
// scopeName [SUCCESS] (2): Logging some data
// 1  'a string'  { key: "Value" }

Log types

The types logs different colors in the console.

const message = 'Some log message'
const data = null // Optional, can be any loggable type

log.debug(message, ...data)     // blue
log.info(message, ...data)      // blue
log.success(message, ...data)   // green
log.todo(message, ...data)      // purple
log.fixme(message, ...data)     // red
log.sequence(message, ...data)  // black
log.danger(message, ...data)    // red
log.warning(message, ...data)   // orange
log.error(message, ...data)     // red

Print only from one scope

// Select scope to only print for
log.only('scopeName')

// OR

// No input scope name defaults to active scope
log.only()

Pause/resume scope type

const type = 'debug' // Or any other type
log.pause(type)
log.resume(type)

// Pause all logs for the log scope (i.e. don't pass type input)
log.pause()

Initialize log scope

import logScope, { init } from 'log-scope'
// OR: import { init } from 'log-scope'

const onErrorCallback = (err, args) => {
  // args = { message, data }

  ... // do something
}

init({
  print: true, // Print to console
  store: true, // Stores all logs in log.history
  conter: true, // Include log counter in print
  onError: onErrorCallback
})

If you're using bugsnag (or other error tracker), use the error callback to send the error-log.

init({
  onError: err => {
    bugsnagClient.notify(err)
  }
})