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

@hoodie/log

v2.1.0

Published

log API for the browser

Downloads

45

Readme

hoodie-log

Custom log API for the browser

Build Status Coverage Status Dependency Status devDependency Status

hoodie-log is a standalone JavaScript library for logging to the browser console. If available, it takes advantage of CSS-based styling of console log outputs.

Example

var log = new Log('hoodie')

log('ohaj!')
// (hoodie) ohaj!
log.debug('This will help with debugging.')
// (hoodie:debug) This will help with debugging.
log.info('This might be of interest. Or not.')
// (hoodie:info) This might be of interest. Or not.
log.warn('Something is fishy here!')
// (hoodie:warn) Something is fishy here!
log.error('oooops')
// (hoodie:error) oooops

var fooLog = log.scoped('foo')
fooLog('baz!')
// (hoodie:foo) baz!

API

Constructor

new Log(prefix)
// or
new Log(options)

Example

var log = new Log({
  prefix: 'hoodie',
  level: 'warn',
  styles: {
    default: 'color: white; padding: .2em .4em; border-radius: 1em',
    debug: 'background: green',
    log: 'background: gray',
    info: 'background: blue',
    warn: 'background: orange',
    error: 'background: red',
    reset: 'background: inherit; color: inherit'
  }
}

log.prefix

Read-only

log.prefix

Prefix used in log messages

Example

log = new Log('hoodie')
log.prefix // hoodie
log.warn("Something is fishy here!")
// (hoodie:warn) Something is fishy here!


log.level

One of debug, info, warn or error. debug is the lowest level, and everything will be logged to the console. error is the highest level and nothing but errors will be logged.

log.level

Example

log.level = 'debug'
log.debug('This will help with debugging.')
// (hoodie:debug) This will help with debugging.
log.level = 'info'
log.debug('This will help with debugging.')
// <no log>
log.level = 'foo'
// throws InvalidValue error

log()

Logs message to browser console. Accepts same arguments as console.log

log("ohaj!")

log.debug()

Logs debug message to browser console if level is set to debug. Accepts same arguments as console.log

log.debug('This will help with debugging.')

log.info()

Logs info message to browser console if level is set to debug or info Accepts same arguments as console.log

log.info('This might be of interest. Or not.')

log.warn()

Logs warning to browser console unless level is set to error Accepts same arguments as console.log

log.warn('Something is fishy here!')

log.error()

Logs error message to browser console. Accepts same arguments as console.log

log.error('oooops')

log.scoped()

log.scoped(prefix)

Returns log API with extended prefix

Example

var log = new Log('hoodie')
log('ohaj!')
// (hoodie) ohaj!
var fooLog = log.scoped('foo')
fooLog('baz!')
// (hoodie:foo) baz!

Testing

Local setup

git clone [email protected]:hoodiehq/hoodie-log.git
cd hoodie-log
npm install

Run all tests and code style checks

npm test

Run all tests on file change

npm run test:watch

Run specific tests only

node tests/specs/debug.js # run .debug() unit tests

PROTIP™: pipe output through a pretty reporter

License

Apache-2.0