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

cloudwatch-winston-wrapper

v2.0.2

Published

Overloads Winston logger with new Transport to publish Metric Data in AWS CloudWatch

Downloads

4

Readme

cloudwatch-winston-wrapper

Simple Node module that allows put Metric Data of the Log Events in CloudWatch AWS through Winston's logger (this is possible by overloading the logger methods of Winston). The Log Events from Winston's logger, put by default two metrics in the namespace indicated to the constructor:

  • instance (instance id from machine AWS), level, Metric Name (always is LogEvent)
  • level, Metric Name (always is LogEvent)

Furthermore, you can configure the level from your logger in CloudWatch. For that, there are the following constants: ERROR, WARN, INFO, DEBUG. By default, level is INFO. Level Logger is ordering by {ERROR, WARN, INFO, DEBUG}. Level ERROR is the most restrictive (only logger.error put metric Data). You can configure Winston's level logger as it describe in Doc's Winston.

You must obtain an instance of cloudwatch-winston-wrapper. For that, it's necessary to specify a JSON with the following fields:

  • namespace : String that specifies the namespace of CloudWatch's Metric. Optionally, you can specify the following fields:
  • region : region from AWS
  • levelCloudWatch : Constant from CloudWatchWinston (CloudWatchWinston.DEBUG, CloudWatchWinston.ERROR...) that specifies the level of CloudWatch's logger. By default is INFO.
  • levelCloudWinston : String ('error', 'warn', 'debug'...) that specifies the level of Winston's logger.
  • dimensions : Array of JSON Array for adding extra dimensions in each metric data in CloudWatch. Each dimension has included the corresponding level. Each array of array contains JSON with the following fields: ** Name : String that represents the name of the dimension ** Value : String that represents the value of the dimension ** Type : (Optionally) String that represents the type of the dimension to generate. This can be the constant allowed AUTO (you can access to this constant through the module), and it represents that the Value must be generate internally. At present, only the instance ID can be generate automatically, and for that, you must specify in the Value the class constant INSTANCE.
  • (other parameters necessary from instance AWS as private key (to see AWS's doc)).

Methods extra to Winston's methods:

  • loadLogger : @argument options : JSON Set the options parameter to the logger. The field options.levelCloudWatch is the level of CloudWatch's logger and options.levelWinston is the level of Winston's logger

Usage

var CloudWatchWinstonWrapper = require('cloudwatch-winston-wrapper');

// First param constructor: namespace from the metrics
// Second param constructor: JSON with the configuration of CloudWatch AWS (region, keys...)
// In this example, we put extra dimensions in each metric data. It will generate four dimensions for each point set in CloudWatch. That dimensions will be: 
// * level, MetricName // By default
// * level, instance, MetricName // By default
// * level, instance, process // Extra
// * level, PID // Extra

var logger = new CloudWatchWinstonWrapper({namespace: "NameSpaceDevelopment", region: "eu-west-1", levelCloudWatch: CloudWatchWinstonWrapper.DEBUG, levelWinston: 'info', 
dimensions: [[{Name: "instance", Value: CloudWatchWinstonWrapper.INSTANCE, Type: CloudWatchWinstonWrapper.AUTO}, {Name: "process", Value: "processName"}], [{Name: "PID", Value: "1024"}]] });

logger.remove(logger.transports.Console);
logger.add(logger.transports.File, { filename: __dirname + "/fileLogs.log", json: false });

logger.info("This is a logger that it put two metric of level INFO in CloudWatch, and it write this in the file 'fileLogs.log' ");

Installing

Via npm:

npm install cloudwatch-winston-wrapper

Via git:

git clone https://github.com/touchvie/cloudwatch-winston-wrapper.git