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

node-cloudwatchlogs

v0.2.0

Published

Logger to AWS CloudWatchLogs and NodeJS

Downloads

31

Readme

INSTALL

npm i node-cloudwatchlogs

USE

First, you should set AWS credentials...

const Logger = require('node-cloudwatchlogs')
Logger.setAWSKeys({
  region: process.env.REGION_AWS,
  accessKeyId: process.env.AWS_ACCESS_KEY_ID,
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
})

Next, you can use the logger on anywhere call to package. Always you need to send the group and the stream names to send to AWS CloudWatchLogs, this is made by config method like example shows. The info,success,warning and error methods shows with colors (blue,green,yellow nad red respectly) the logs in NodeJS and put this state in the AWS Logs.

require('dotenv').config();
const Logger = require('node-cloudwatchlogs');
Logger.setAWSKeys({
  region: process.env.REGION_AWS,
  accessKeyId: process.env.AWS_ACCESS_KEY_ID,
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
})

Logger.setConfig({
  env: process.env.NODE_ENV || 'development', // it could takes from the NODE_ENV if you don't put anything
  logger: { // to aws cloudt logs send
    maxLine: 10, // max numbers for lines in each log
    countMsgToSend: 20, // numbers of logs group to send (each 20 messages)
    maxLevel: 3 // objects depth to send
  },
  logConsole: { // logs for nodejs
    show: true, // if you want to show the logs in the node logs
    maxLine: 15, // max lines to show
    maxLevel: 2 // objects depth to show
  }
})

const logGroup1Stream1 = Logger.config(
  'TEST', // logs group
  `EXAMPLE 1` // logs stream for each group
)

const logGroup1Stream2 = Logger.config(
  'TEST', // logs group
  `EXAMPLE 2`, // logs stream for each group
)

const logGroup2Stream1 = Logger.config(
  'TEST1', // logs group
  `EXAMPLE 1`, // logs stream for each group
)

const logGroup2Stream2 = Logger.config(
  'TEST1', // logs group
  `EXAMPLE 2`, // logs stream for each group
  {
    environment: 'staging',
    logger: { // to aws cloudt logs send
      maxLine: 10, // max numbers for lines in each log
      countMsgToSend: 20, // numbers of logs group to send (each 20 messages)
      maxLevel: 3 // objects depth to send
    },
    logConsole: { // logs for nodejs
      show: true, // if you want to show the logs in the node logs
      maxLine: 15, // max lines to show
      maxLevel: 2 // objects depth to show
    }
  }
)

logGroup1Stream1.info('EXAMPLE VOCALS', 'A')
logGroup1Stream1.info('EXAMPLE VOCALS', 'B')
logGroup1Stream1.error('EXAMPLE VOCALS', 'C')
logGroup1Stream2.error('EXAMPLE VOCALS', 'D')
logGroup1Stream2.error('EXAMPLE VOCALS', 'E')
logGroup1Stream2.warning('EXAMPLE VOCALS', 'F')

setTimeout(() => {
  logGroup1Stream1.warning('EXAMPLE VOCALS', 'G')
  logGroup1Stream1.warning('EXAMPLE VOCALS', 'H')
  logGroup1Stream1.success('EXAMPLE VOCALS', 'I')
  logGroup1Stream1.success('EXAMPLE VOCALS', 'J')
  logGroup1Stream2.success('EXAMPLE VOCALS', 'K')
  logGroup1Stream2.success('EXAMPLE VOCALS', 'L')
  logGroup1Stream2.success('EXAMPLE VOCALS', 'M')
}, 5000)

setTimeout(() => {
  logGroup2Stream1.info('EXAMPLE WHIT NUMBERS', 1)
  logGroup2Stream1.info('EXAMPLE WHIT NUMBERS', 2)
  logGroup2Stream1.info('EXAMPLE WHIT NUMBERS', 3)
  logGroup2Stream2.error('EXAMPLE WHIT NUMBERS', 4)
  logGroup2Stream2.error('EXAMPLE WHIT NUMBERS', 5)
  logGroup2Stream2.error('EXAMPLE WHIT NUMBERS', 6)
}, 8000)

setTimeout(() => {
  logGroup2Stream1.warning('EXAMPLE WHIT NUMBERS', 7)
  logGroup2Stream1.warning('EXAMPLE WHIT NUMBERS', 8)
  logGroup2Stream1.warning('EXAMPLE WHIT NUMBERS', 9)
  logGroup2Stream2.success('EXAMPLE WHIT NUMBERS', 10)
  logGroup2Stream2.success('EXAMPLE WHIT NUMBERS', 11)
}, 9000)

require('net').createServer().listen();

NodeJS Logs

NODEJS LOGS

AWS groups

GROUPS AWS LOGS

AWS streams for a group

STREAMS FOR A GROUP AWS LOGS