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

@cisl/logger

v1.2.2

Published

Logging function that prints time-stamped strings or JSON objects to the console.

Downloads

7

Readme

@cisl/logger

This is a NPM module that wraps around the winston logging library to take advantage of the cog.json file for configuration. This allows for easier usage within cogs as it does not require knowing the boilerplate of using winston and the parts of the cog.json. This is largely compatible with the existing function/usage of @cel/logger.

Installation

npm install @cisl/logger

Usage

const logger = require('@cisl/logger');
logger.debug('debug');
logger.verbose(1);
logger.info('info');
logger.warn({test: 'aaaa', foo: 'bar'});
logger.error('error');
logger.setLogLevel('warn');
logger.logExpression('some message', 'info');
logger.logExpression('some error', 0);

Note: For logging throw exceptions, you should either cast it to a string (e.g. logger.info(`${new Error('test')}`))) or pass specific parts of the exception as strings:

const err = new Error('test');
logger.error(err.message);
logger.error(err.stack);

Attempting to log the Error object as-is will end up with just logging undefined.

Configuration

As stated above, the logger uses the cog.json file in the current working directory to configure itself. By default, the logger will always log to console and be set to a level of info. This can be tuned, as well as adding additional transports, by adding a logging block to the cog.json, using the following keys:

{
  logging: {
    info: "level" // String specifying level to log at, defaults to 'info'
    console: true | false // Boolean flag to turn on/off console logging, defaults to true.
    file: "filename" // string for file to write log to
    db: true | false // Boolean flag to turn on/off logging to MongoDB, defaults to false
  }
}

If no cog.json exists, then it uses a default of log level info and uses the console.

Function Signatures

  • error(msg: string | object): void
  • warn(msg: string | object): void
  • info(msg: string | object): void
  • debug(msg: string | object): void
  • setLogLevel(level: string | number): void
  • logExpression(msg: string | object, level: string | number)

Where msg is the message to log and then level is a specific log level to use (see below).

Log Levels

The setLogLevel and logExpression functions both allow passing in a string or number to them. Strings should be equal to one of the following available levels:

  • error
  • warn
  • info
  • debug

Each of these strings can also be used as the function name on the logger object:

logger.error(msg);
logger.warn(msg);
logger.info(msg);
logger.verbose(msg);
logger.debug(msg);
logger.silly(msg);

If you use a number, these correspond to the following levels (being backwards compatible with @cel/logger):

const levels = {
  0: error,
  1: warn,
  2: info,
  3: debug
}