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

eris-logger

v1.0.4

Published

Logger

Downloads

11

Readme

ErisLogger

About package

ErisLogger is a logging tool that makes life easier. It has under the hood a pino package for writing logs to a file as well as tools for console logging.

Installation

npm i eris-logger

Example

General concepts

The default settings create a logger that will write to the terminal and file. The logger also includes the following settings:

  • Terminal Settings
  • FileLogger settings
  • Date format
  • Logging level
const logger = new ErisLogger({
  terminal: { ... },
  file: { ... },
  options: {},
});

Logging levels can be different: for example, one configuration can be configured for a terminal, another for a file, or you can set a global one for all.

How it looks like:

const logger = new ErisLogger({
  terminal: {
    use: true,
    options: {
      levels: ['info', 'debug']
    }
  },
  file: {
    use: true,
    options: {
      levels: ['warning', 'error', 'critical']
    } 
  },
});

Or global:

const logger = new ErisLogger({
  options: {
    levels: ['info', 'alert', 'debug', 'warning', 'error', 'critical']
  },
});

Terminal

To begin with, let's create an instance of the ErisLogger class, after which we indicate that we need to output logs in the terminal.

const logger = new ErisLogger({ terminal: { use: true, options: {} } });

This is how the default settings look like:

const terminalConfig = {
  use: true,
  options: {
    colors: {
      info: 'greenBright',
      alert: 'blueBright',
      debug: 'blackBright',
      warning: 'yellow',
      error: 'redBright',
      critical: 'bgRed',
    },
    levels: ['info', 'alert', 'debug', 'warning', 'error', 'critical'],
  },
};


const logger = new ErisLogger({ terminal: terminalConfig });

List of all available colors:

export type TerminalColors = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white';
export type TerminalBgColors = 'bgBlack' | 'bgRed' | 'bgGreen' | 'bgYellow' | 'bgBlue' | 'bgMagenta' | 'bgCyan' | 'bgWhite';

export type TerminalBrightColors =  | 'blackBright'  | 'redBright'  | 'greenBright'  | 'yellowBright'  | 'blueBright'  | 'magentaBright'  | 'cyanBright'  | 'whiteBright';
export type TerminalBgBrightColors =  | 'bgBlackBright'  | 'bgRedBright'  | 'bgGreenBright'  | 'bgYellowBright'  | 'bgBlueBright'  | 'bgMagentaBright'  | 'bgCyanBright'  | 'bgWhiteBright';

FileLogger

To begin with, let's create an instance of the ErisLogger class, after which we indicate that we need to output logs in the file.

const logger = new ErisLogger({ file: { use: true, options: {} } });

This is how the default settings look like:

const fileConfig = {
  use: true,
  options: {
    dir: '/logs.log',
    colorize: true,
    levels: ['info', 'alert', 'debug', 'warning', 'error', 'critical'],
  },
};


const logger = new ErisLogger({ file: fileConfig });

WSLogger (ErisLoggerCenter)

First, you need to deploy a logger center instance.

Now let's create an instance of the ErisLogger class, and then specify that we need to output logs to the logger center.

const logger = new ErisLogger({ ws: { use: true, options: {} } });

This is how the default settings look like:

const wsConfig = {
  use: true,
  options: {
    hostname: 'localhost',
    port: 5000,
    auth: {
      projectId: 'your project id...',
      secret: 'your secret...',
    },
    levels: ['info', 'alert', 'debug', 'warning', 'error', 'critical'],
  },
};


const logger = new ErisLogger({ ws: wsConfig });

Methods

// Info log
logger.info({ title: 'INFO', message: 'info string', params: { foo: 'bar' } });

// Alert log
logger.alert({ title: 'ALERT', message: 'alert string', params: { foo: 'bar' } });

// Debug log
logger.debug({ title: 'DEBUG', message: 'debug string', params: { foo: 'bar' } });

// Warning log
logger.warning({ title: 'WARNING', message: 'warning string', error: new Error('Some warning') });

// Error log
logger.error({ title: 'ERROR', message: 'error string', error: new Error('Some error') });

// Critical log
logger.critical({ title: 'CRITICAl', message: 'critical error string', error: new Error('Some critical error') });