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-less-fancy

v1.4.0

Published

Logging in both Node and the browser the less fancy way

Downloads

35

Readme

log-less-fancy

Renovate enabled Build Status Dependency Status devDependency Status

Logging in both Node and the browser the fancy way using the debug module with an API that provides log levels.

output

Installation

npm i -S log-less-fancy

Usage

The package exports a single function, which takes the namespace of your module as an argument and returns the logger API.

// logger.js
const logger = require("log-less-fancy")("myNamespace");

logger.info("This is not a monolith, but your mother is");
logger.warn("oiii mate, watch out");
logger.success("whee");
logger.debug("why is this even working?");
logger.log("hello");
logger.error("dis is broke m8");
logger.fatal("shit went wrong D:");

Now execute the script:

# Prints all messages and all fatal errors
DEBUG='*' node logger.js

# Prints only warnings and all fatal errors
DEBUG=*WARN* node logger.js

# Prints only messages in your namespace and all fatal errors
DEBUG=*myNamespace* node logger.js

Node API

The logger API consists of 8 methods, namely fatal, error, success, warn, info, debug and log. All methods act like the native console API and take as many arguments as you like.

The fatal method is the only one with divergent behavior:

  • It traces the log up to the source file which triggered it which helps to debug the exception if necessary.
  • It will always be rendered and does not use the DEBUG environment variable / the debug module since it doesn't make sense to not to print fatal errors at any time.
  • It exits the process with code 1 which identifies the Node process as crashed.

Browser API

The logger API in the browser is aligned to the Node API, but only uses the native console object to save some bytes down the wire, so no debug fancy colored output here.

Advanved features and methods

.enforceLogging()

Enforces the log output to be shown. Useful if you cannot set the DEBUG env variable yourself.

Roadmap / Features to develop

  • [ ] Add adapters / plugins, e.g. a plugin which forwards all messages to the fs or some logging service. #1
  • [ ] Make the configuration possible via a .fancylogrc which will be resolved from the root folder of the processes package . #2

Code style

Please make sure that you adhere to the code style which is based upon xo.

Licensing

See the LICENSE file at the root of the repository.