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

wis-logger

v0.0.4

Published

A unified logger created by IBM Watson in Support team that integrates multiple logging mechanisms.

Downloads

54

Readme

Watson in Support logger

Custom logger created by the IBM Watson in Support team that integrates multiple log mechanisms together in order to provide a unified logging experience across different apps. Current logging mechanisms:

  • Console
  • Cloudant database

Installation

npm install wis-logger

Features

  • Core logging functionality based on the bunyan logger.
  • Integrates bunyan-format module to enhance bunyan log record formatting.
  • Adds additional Cloudant logging capabilities to create log documents to any Cloudant database.
  • Provides ability to customize Cloudant log document format.

Introduction

Here's an example on how to create a basic Console logger.

const logger = require('wis-logger')({
    appName: 'logger-basic',
    level: 'DEBUG', 
});
logger.debug('A debug message');
logger.info('An info message');
logger.warn('A warning message');
logger.error('An error message');

The basic Console logger will produce this output:

[2017-10-29T21:58:58.919Z] DEBUG: logger-basic/17842 on ntsang-ibm.local: A debug message
[2017-10-29T21:58:58.922Z]  INFO: logger-basic/17842 on ntsang-ibm.local: An info message
[2017-10-29T21:58:58.922Z]  WARN: logger-basic/17842 on ntsang-ibm.local: A warning message
[2017-10-29T21:58:58.922Z] ERROR: logger-basic/17842 on ntsang-ibm.local: An error message

Here's an example of a logger with both Console logging and Cloudant logging.

const logger = require('wis-logger')({
    appName: 'logger-cloudant',
    level: 'DEBUG',
    console: true,
    cloudant: true,
    cloudantUrl: 'https://account.cloudant.com/logs',
    cloudantUsername: 'username',
    cloudantPassword: 'password',
    cloudantLogHistory: true,
});
logger.debug({message: 'A debug message'});
logger.info({message: 'An info message'});
logger.warn({messag`e: 'A warning message'});
logger.error({message: 'An error message'});

The Console/Cloudant logger will product this output:

[2017-10-29T21:58:58.929Z] DEBUG: logger-cloudant/17842 on ntsang-ibm.local:  (message="A debug message")
[2017-10-29T21:58:58.947Z]  INFO: logger-cloudant/17842 on ntsang-ibm.local:  (message="An info message")
[2017-10-29T21:58:58.950Z]  WARN: logger-cloudant/17842 on ntsang-ibm.local:  (message="A warning message")
[2017-10-29T21:58:58.951Z] ERROR: logger-cloudant/17842 on ntsang-ibm.local:  (message="An error message")

Each logger call will also create a Cloudant document with this default format:

{
  "_id": "607f6ddff4629c4516eac6169959bfed",
  "_rev": "1-e4dffd5dfff029d22f6924c49d0e85a7",
  "timestamp": "2017-10-31T00:17:52.326Z",
  "severity": "WARN",
  "hostname": "ntsang-ibm.local",
  "appName": "logger-examples",
  "pid": 25801,
  "message": "loggerCloudant debug test"
}

You may also find situations where you want to create a logger at a later stage in your program or you want to dynamically create a logger on the fly. For these situations you can use the createLogger function.

const wisLogger = require('wis-logger');
const logger = wisLogger.createLogger({
    appName: 'logger-from-create',
    level: 'DEBUG', 
});
logger.debug({message: 'A debug message'});

When logging to Cloudant you may want to customize the format of the log record. You can do this by creating your own custom log record object and passing it to the logger.

function CustomLogRecord(logRecord) {
    this.timestamp = logRecord.time;
    this.severity = logRecord.level;
    this.hostname = logRecord.hostname;
    this.appName = logRecord.name;
    this.pid = logRecord.pid;
    this.field1 = logRecord.field1;
    this.field2 = logRecord.field2;
}
const logger = require('wis-logger')({
    appName: 'logger-cloudant',
    level: 'DEBUG',
    console: true,
    cloudant: true,
    cloudantUrl: 'https://account.cloudant.com/logs',
    cloudantUsername: 'username',
    cloudantPassword: 'password',
    cloudantLogDocument: CustomLogRecord,
    cloudantLogHistory: true,
});
logger.debug({ field1: "field1 value", field2: "field2 value" });