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

better-call-log

v1.0.5

Published

![alt BetterCallLogo](https://raw.githubusercontent.com/skullab/better-call-log/master/images/better_call_log_enhanced_logo.png)

Downloads

22

Readme

alt BetterCallLogo

Installation

npm install better-call-log

NOTE: The enhanced version is available from release 1.0.x Old versions are no longer compatible.

Usage

import BetterCall from "better-call-log"

const logger = new BetterCall.Logger();
logger.debug("Hello World !");

// example output : 
// 2023-09-25T15:15:53.291Z DEBUG Logger : Hello World !

Options

const logger = new BetterCall.Logger({
    name: "MyLogger",
    severities: BetterCall.Severity.WARNING,
    formatter: new BetterCall.CSSFormatter(),
    transports: [new BetterCall.ConsoleTransport()]
});

When you create a new instance of a logger you can define the logger options.

name:string - the name of the logger
severities:Severity - the minimum severity to fire log
formatter:ILoggerFormatter - the formatter to use, by default is SimpleFormatter
transports:ILoggerTransport[] - the transports to use, by default is ConsoleTransport

Severities

BetterCallLog implements the Syslog Protocol (RFC 5424). In descending order of severity, these log levels are: emergency, alert, critical, error, warning, notice, info, and debug.

logger.emergency('some important message...');
logger.alert('some important message...');
logger.critical('some important message...');
logger.error('some important message...');
logger.err('some important message...'); // alias of error
logger.warning('some important message...');
logger.warn('some important message...'); // alias of warning
logger.notice('some important message...');
logger.log('some important message...'); // alias of notice
logger.info('some important message...');
logger.debug('some important message...');

with the severities option it is possible to limit the sending of messages to a certain level.

const logger = new BetterCall.Logger({
    name: "MyLogger",
    severities: BetterCall.Severity.WARNING,
    formatter: new BetterCall.CSSFormatter(),
    transports: [new BetterCall.ConsoleTransport()]
});
logger.emergency('some important message...');
logger.alert('some important message...');
logger.critical('some important message...');
logger.error('some important message...');
logger.err('some important message...'); // alias of error
logger.warning('some important message...');
logger.warn('some important message...'); // alias of warning

// the messages below will not be sent
logger.notice('some important message...');
logger.log('some important message...'); // alias of notice
logger.info('some important message...');
logger.debug('some important message...');

Formatters

All messages are converted according to the syslog protocol specifications. Subsequently, using a formatter it is possible to format the message according to a specific model.

Available formatters:

  • ANSIFormatter
  • CSSFormatter
  • JSONFormatter
  • SimpleFormatter
  • StringFormatter
  • SyslogFormatter

if the formatter is not defined, the default formatter is SimpleFormatter.

Tranports

The transport object has the task of transporting the message to a specific output. It is possible to define more than one tranport in the logger options.

Available transports:

  • ConsoleTransport
  • FileTransport
  • HttpTransport
  • IndexedDBTransport

If a transport is not defined, the default transport is ConsoleTransport.

Add transport at run-time, specify a temporary transport

You can add or remove a transport at run-time with addTransport and removeTransport.

const logger = new BetterCall.Logger({
    transports: [new BetterCall.ConsoleTranport()]
});
logger.addTransport(new BetterCall.HttpTransport({
    method: "post",
    url: "http://localhost/logs",
}));
logger.debug("Hello World !");

To specify a temporary transport use the to function

const logger = new BetterCall.Logger({
    transports: [new BetterCall.ConsoleTranport()]
});
// define new temporary tranport at run-time
logger.to(new BetterCall.HttpTransport({
    method: "post",
    url: "http://localhost/logs",
})).debug("Hello World !");

// or define it by name
const logger = new BetterCall.Logger({
    transports: [
        new BetterCall.ConsoleTranport(),
        new BetterCall.HttpTransport({
            name:'http'
            method: "post",
            url: "http://localhost/logs",
        })
    ]
});
logger.to('http').debug("Hello World !");

NOTE: Temporary tranports are only used once. By defining the transport by name, any other transports defined in the logger options will not be executed.

Add a TAG

You can define a TAG for the log message.

const logger = new BetterCall.Logger({
    transports: [new BetterCall.ConsoleTranport()]
});
logger.debug('MYTAG','hello world');

// example output : 
// 2023-09-25T15:14:40.661Z DEBUG Logger::MYTAG : hello world

This way the tag is set dynamically, but it is possible to define a global TAG.

const logger = new BetterCall.Logger({
    transports: [new BetterCall.ConsoleTransport()]
});
logger.setTag('MYTAG');
logger.debug('hello world');
logger.debug('an other message');

it is possible to define a temporary TAG with the withTag function.

const logger = new BetterCall.Logger({
    transports: [new BetterCall.ConsoleTransport()]
});
logger.setTag('MYTAG');
logger.debug('hello world');
logger.withTag('OTHERTAG').debug('an other message');
logger.info('important message');

// example output : 
// 2023-09-25T15:17:43.598Z DEBUG Logger::MYTAG : hello world
// 2023-09-25T15:17:43.599Z DEBUG Logger::OTHERTAG : an other message
// 2023-09-25T15:17:43.600Z INFO Logger::MYTAG : important message