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

femto-logger

v1.0.1

Published

a small logging utility

Downloads

5

Readme

femto-logger

A small, flexible logger for Node.js

Desired Features

  • Small and easy to use. Configure (or don't) and forget it.
  • Different levels of reporting (DEBUG, INFO, WARNING, ERROR, FATAL)
  • Level-based ANSI coloring
  • UTC-based Timestamping
  • printf-style formatting of messages

Usage

Usage is pretty basic:

const logging = require('femto-logging');
logging.info('Something happened.');

which will yield something like:

2014-02-18T23:34:12+00:00 [INFO] Something happened.

Coloring

Femto-logger uses ANSI coloring to color the log line according to the level.

The colors can be altered to your liking as such:

logging.config.colors.debug = logging.BRIGHT_CYAN;

The defaults are as follows:

  • DEBUG: DARK_WHITE
  • INFO: BRIGHT_WHITE
  • WARNING: BRIGHT_YELLOW
  • ERROR: BRIGHT_RED
  • FATAL: BRIGHT_MAGENTA

Possible values are: DARK_BLACK, DARK_RED, DARK_GREEN, DARK_YELLOW, DARK_BLUE, DARK_MAGENTA, DARK_CYAN, DARK_WHITE, BRIGHT_BLACK, BRIGHT_RED, BRIGHT_GREEN, BRIGHT_YELLOW, BRIGHT_BLUE, BRIGHT_MAGENTA, BRIGHT_CYAN, BRIGHT_WHITE, and NONE

It can also be disabled, which is equivalent to setting all colors to NONE:

logging.config.coloring = false;

Timestamping

Timestaamps default to UTC (GMT) for consistency, though the exact time is still based on the system clock and not an external time source. The default format is ISO 8601.

The format can be changed as such:

logging.config.date.format = 'YYYY-MM-DDTHH:mm:ssZ';

There is currently a single constant ISO8601 that can be used to reset the value.

The format of the date string is determined by the underlying moment instance.

As of 1.0.0, the option to have dates returned in the local timezone has been added:

logging.config.date.local = true;

Labels

Level labels can also be altered as such:

logging.config.labels.debug = 'DEBUG';

Message Formatting

Messages can be formatted using printf-style placeholders:

logging.debug('These are placeholders: %s, %d', 'abc', 789);

More information on usage of placeholders is available at the node-printf project website.

Return Values

In addition to messages being logged to the console, they are also returned from the logging function:

const message = logging.debug('Now the message variable has this content as well.');

Messages are logged to the console by default, but can be turned off easily:

logging.config.console.suppress = true;

Change log

0.0.1

  • Initial release

0.0.2

  • Added printf formatting
  • Added more unit tests
  • Added examples

1.0.0

  • Updated to ES5 syntax
  • Locked down dependency versions in package.json
  • Reorganized code for better readability
  • Added option for local timezone timestamps
  • Added examples for color disabling and local timestamps

1.0.1

  • Security update to dependencies