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

@bitchcraft/unicorn-logger

v1.3.1

Published

A fancy wrapper for debug with full Console Web API support.

Downloads

356

Readme

@bitchcraft/unicorn-logger

             ,
          „„/,
         / (×\
   ,—~~~’ / `-'    UnicornLogger
  /( )__( )   ́ ́ ́           1.2.0
 ‘ //   //    ́ ́ ́ ́ ́  
   ``   ``   ́ ́ ́ ́ ́ ́ ́ ́

A fancy wrapper for debug that supports all Console Web API methods and allows chaining.

CircleCI

Installation

$ yarn add @bitchcraft/unicorn-logger
$ npm install -P @bitchcraft/unicorn-logger

Usage

UnicornLogger optimizes debug for writing to the browser console, but is also usable in NodeJS. It binds all Console Web API methods to debug with graceful fallbacks.

As with debug you can control the logging output with the DEBUG env (NodeJS) or a localStorage key debug. Values are a string with wildcards (e. g. api:*,-api:auth*,-*info*,*important*).

Create a new logger instance by calling the UnicornLogger constructor with a namespace (string). The new logger instance is directly callable (defaults to log) and exposes the following methods on top. All methods return a reference to the instance to allow method chaining.

ES6 example

import UnicornLogger from '@bitchcraft/unicorn-logger';

const logger = new UnicornLogger('myNamespace');
logger.group('new console group')
	.log('some stuff: %O', { logger })
	.warn('Oops. There is some unicorn barf on the ground.')
	.error('Something went seriously wrong here')
	.groupEnd();

ES5 example

var UnicornLogger require('@bitchcraft/unicorn-logger');
var logger = UnicornLogger('myNamespace');

logger.group('new console group')
	.log('some stuff: %O', { logger })
	.warn('Oops. There is some unicorn barf on the ground.')
	.error('Something went seriously wrong here')
	.groupEnd();

Supported methods

| Method | Parameters | Description | |:----------------------------------------------------------------------------------------- |:-------------------------------------- |:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | assert | assertion: boolean, ...obj: Any | Writes an error message to the console if the assertion is false. If the assertion is true, nothing happens. | | clear | | Clears the console | | error | ...obj: Any | Outputs an error message to the console | | group | label: string | Creates a new inline group in the Web Console log. This indents following console messages by an additional level, until groupEnd() is called. | | groupCollapsed | label: string | Creates a new collapsed inline group in the Web Console log. | | groupEnd | | Exits the current inline group in the Web Console. | | info | ...obj: Any | Outputs an informational message to the Web Console. Most browsers prefix these messages with an (i)-icon. | | log (alias: debug) | | Outputs a message to the console. | | table | data: Array or Object, columns: Object | Displays tabular data as a table. | | time | label: string | Starts a timer you can use to track how long an operation takes. You give each timer a unique name, and may have up to 1,000 timers per instance. When you call console.timeEnd() with the same label, the elapsed time in milliseconds since the timer was started will be written to the console. | | timeEnd | label: string | Stops a timer that was previously started by calling time(). | | trace | ...obj: Any | Outputs a stack trace to the console. | | warn | ...obj: Any | Outputs a warning message to the console. |

ES2015+ import with flow types

// babel: env, stage-0, flow
import UnicornLogger from '@bitchcraft/unicorn-logger/src/UnicornLogger';

Plugins/Middlewares

UnicornLogger can be extended trough middlewares/plugins. A middleware can:

  • react to logging calls
  • manipulate call arguments
  • cancel the further execution of logging calls
  • register its own logging functions

Middlewares can be easily added to an instance or globally to the logger Class. Global middlewares are applied before instance ones, both will be executed in the order they were added.

import UnicornLogger from '@bitchcraft/unicorn-logger';

const logger = new UnicornLogger('myNamespace');
logger.use(new ExampleMiddleware()); // Instance Middleware
UnicornLogger.use(new ExampleMiddleware()); // Global Middleware

For middleware development see the wiki

Bundle size

About core-js takes up roughly 62% of the bundle size, which should not increase your bundle size if you are running babel. After minification, the gzipped size (including core-js) should be around 13KB. You can check out the bundle analytics for the non-minified bundle.

Help and feedback

Please file issues in Github

Contribute

We are open for PRs. Please respect to the linting rules.

License

UnicornLogger is free software und the BSD-3-Clause (see LICENSE.md). The unicorn UTF8 art is CC-Attribution 2018 Josh Li.

Contributors