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

@rmtc/logger

v1.0.0

Published

Consistent logging for the @rmtc/toolchain CLI

Downloads

116

Readme

@rmtc/logger

Consistent logging for the @rmtc/toolchain CLI.

[!WARNING] This package is intended for internal use by @rmtc/toolchain. It's probably not useful by itself.

[!WARNING] This project is intended for use in @rowanmanning's projects. It's free to use but I don't offer support for use-cases outside of what I need.

Table of Contents

Requirements

This library requires the following to run:

Usage

Install the module with npm:

npm install @rmtc/logger

This module exports a Logger class which is used to provide consistent logging for the command line interfaces:

const {Logger} = require('@rmtc/logger');
const logger = new Logger();
logger.info('Hello World!');

Logging

The logger has different log methods depending on the level of log you want to output:

logger.debug('This is a debug-level message');
logger.info('This is an info-level message');
logger.warn('This is a warning message');
logger.error('This is an error message');

The error method can also accept an Error object, which it will render neatly:

logger.error(new Error('something went wrong));

Configuration

When you create a logger, you can configure it with the following options by passing them as part of an options object:

const logger = new Logger({
    // options go here
});

The available options are:

logLevel

String. The lowest log level to output logs for. Any less important log than this level will not be output. Defaults to process.env.LOG_LEVEL, and if that's not set then info. E.g.

const logger = new Logger({ logLevel: 'warn' });
logger.info('shh'); // Logs nothing

prefix

String. A string to prepend to all log messages from the logger. A space will be added to separate the prefix from the message. Defaults to an empty string. E.g.

const logger = new Logger({ prefix: 'Hello' });
logger.info('World!'); // Logs "Hello World!"

Child loggers

If you want to chain prefixes together, you can create child loggers. These inherit the settings from their parent but you can add a further prefix. E.g.

const logger = new Logger({ prefix: 'one' });
logger.info('testing'); // Logs "one testing"

const childLogger = logger.child({ prefix: 'two' });
logger.info('testing'); // Logs "one two testing"

Contributing

See the central README for a contribution guide and code of conduct.

License

Licensed under the MIT license. Copyright © 2023, Rowan Manning