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

@whi/weblogger

v0.4.0

Published

A minimal logger implementation designed to work in web browsers

Downloads

254

Readme

new Logger( context, level )

This micro-package provides a minimalist logging class for web browsers.

Overview

Bundled size is less than 2KB

Install

npm i @whi/weblogger

Usage

Browser

<script src="weblogger.bundled.js"></script>

<script type="text/javascript">
    const { Logger } = WebLogger;
    const log = new Logger( "main" );

    log.fatal("Testing");
    log.error("Testing");
    log.warn("Testing");
    log.normal("Testing"); // default level
    log.info("Testing");
    log.debug("Testing");
    log.trace("Testing");
</script>

Node

const { Logger } = require('@whi/weblogger');

const log = new Logger( "main", "debug" );

log.fatal("Testing");
log.error("Testing");
log.warn("Testing");
log.normal("Testing");
log.info("Testing");
log.debug("Testing");
log.trace("Testing"); // would not log

Set defaults using localStorage

window.localStorage.setItem("LOG_COLOR", "false"); // turn off coloring
window.localStorage.setItem("LOG_LEVEL", "debug"); // set default level to "debug"

Avoiding expensive arg computations

Short-circuit using logical operators

log.level.debug && log.debug("Expensive arg computation: %s", value.map(...).join(", ") );

Or, a callback function that only evaluates when a message will be logged.

log.debug("Expensive arg computation: %s", () => [ value.map(...).join(", ") ]);

API Reference

new Logger( context, level, colors )

Change this Logger's verbosity level.

  • context - (required) an identifier used in the log format
  • level - (optional) the starting log level
    • defaults to level 3 (normal)
  • colors - (optional) a boolean for log coloring
    • defaults to true

<Logger>.setLevel( level )

Change this Logger's verbosity level.

  • level - (required) the new log level

Returns the integer value of the new level.

Contributing

See CONTRIBUTING.md