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

@reallyuseful/logger

v1.0.0-alpha.2

Published

A useful and simple Node.js logging system.

Downloads

1

Readme

@reallyuseful/logger

A simple and extensible logging system for Node.js.

👷 Under development

const { Logger } = require('@reallyuseful/logger');
const myLogger = new Logger();
myLogger.info('🌍 Hello, world!');
myLogger.err('💥 An error occurred.', { context: 42 });

Screenshot

Logging to external services

You can log to multiple services at once.

Promises

Each logging function returns a Promise that is resolved once all the transports have finished logging.

Usage

const logger = new Logger([array of Transports]);
  • If you don’t provide any transports, you’ll get a ConsoleTransport.
  • Logging functions are named after the syslog severity levels. Here they are, from least- to most-severe:
logger.debug(…);
logger.info(…);
logger.notice(…);
logger.warning(…);
logger.err(…);
logger.crit(…);
logger.alert(…);
logger.emerg(…);

You can pass anything as arguments to these functions. It’s common to pass a string as the first argument, followed by additional objects that you want to log. (Just like console.log.)

logger.info(
  'This is a string',
  { extraInfo: 42 },
  [ 'Gryffindor', 'Hufflepuff', 'Ravenclaw', 'Slytherin' ]
);

Options for ConsoleTransport

ConsoleTransport can be customized with the following options:

  • level (Level): Don’t log anything below this severity level. Default: log everything
  • color (boolean): If true, console output is colorized. Default: true
  • timestamps (boolean): If true, console output is prefixed with the current timestamp. Default: true
  • prefix (string): If provided, prefix each log message’s details with this string.
const transport = new ConsoleTransport({ <options> });
const logger = new Logger(transport);

Add your own logging service

To log to a service that isn’t listed above, you can create your own Transport.

A Transport is any object with the following properties:

  • A log() method
  • A level property (optional)

log(level, ...details)

The log method takes a severity level as its first argument. Additional arguments are the details to be logged.

The log method returns a Promise, and you should not resolve it until logging is complete. For example, if you are logging to a file, don’t resolve the Promise until the message has been written to disk.

level optional property

If your transport object has a level property, this is the minimum severity to be logged. For example if your object has a level property that is set to Level.warning, then your transport will receive log messages for warning, err, crit, alert and emerg, but not for debug, info or notice.

const verySimpleTransport = {
  level: Level.warning,
  log: (level, ...details) => {
    console.log(Level[level], ...details);
    return Promise.resolve();
  }
};