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

aws-logging

v1.2.6

Published

Logs activity across all services under a single AWS account. Optional features can be enabled to trigger Email notifications based on the logs severity level

Downloads

4

Readme

aws-logging

Logs activity across all services under a single AWS account. Optional features can be enabled to trigger Email notifications based on the logs severity level.

JavaScript Node AWS Dynamo Lambda SES

Installation

Install the Package

  npm install aws-logging

Import the module

 let Logger = require('aws-logging');

Configure your logger

 Logger.config.update(
    {
        tableName : "SERVICE-LOGS",  
        mailList : ["[email protected]"],
        stage : "Dev",
        mailSubject : "New AWS Log",
        sourceEmail : "[email protected]",
        notifyOnSeverityLevel : 10,
        serviceName : "sample-service",
        enableNotifications : false,
        region : "us-east-2",
        accessKeyId : "xxxx",
        secretAccessKey : "xxxx"

    });

IMPORTANT :

Make sure the IAM role has the following permissions enabled on AWS AND in your app.

(The role you generated your Access Key and Secret from)

  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "logs:*"
      Resource: "*" 
    - Effect: "Allow"
      Action:
        - "dynamodb:*"
      Resource: "*"
    - Effect: "Allow"
      Action: "ses:ListIdentities"
      Resource: "*" 
    - Effect: "Allow"
      Action: "ses:SendEmail"
      Resource: "*"

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | tableName | String| Required. The name of the table that will be automatically created to store your logs. Defaults to "SERVICE-LOGS". Must be unique from other table names. | | mailList | Array | Optional. A list of recipient emails that will recieve log alerts | | mailSubject | String | Optional. The email subject to be displayed for recipients when they recieve a log alert. Defaults to "New AWS Log" | | sourceEmail | String | Optional. The sender email used to send the logs. Must be a verified email in your AWS account or under a verified Domain | | notifyOnSeverityLevel | Integer | Required. The severity level a log must have in order to trigger an email alert. Defaults to 10. (max 10 - min 0) | | serviceName | String | Required. The name of the service you added this package to. This will be used to identify which service the log belongs to in the SERVICE-LOGS table | | enableNotifications | Boolean | Optional. Specify if you want email alerts enabled. Note : If set to true, The following fields will be required : mailList, and sourceEmail . | | region | String | Required . The AWS region you want this Logger configured for. Note : Must be the same as the region that the sourceEmail is configured for in your AWS account | | accessKeyId | String | Required . Your AWS IAM access Key. Not required if you dont have to configure this before using aws-sdk in your service | | secretAccessKey | String | Required . Your AWS IAM secret Key. Not required if you dont have to configure this before using aws-sdk in your service |

Usage

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | message | String| Required. The message you want to log | | severity | Array | Optional. Severity level (max 10 - min 0). Defaults : {Log : 1 , Warn : 2 , Error : 3} | | details | JSON Object | Optional. Any additional details you may want to add. Defaults to false |

Partial example from this example app

var express = require('express');
const serverless = require('serverless-http');
var app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
const Logger = require("aws-logging");

Logger.config.update({
  
    mailList : [process.env.RECIEVER_EMAIL_1],
    sourceEmail : process.env.SOURCE_EMAIL,
    notifyOnSeverityLevel : 5,
    serviceName : process.env.SERVICE_NAME,
    enableNotifications : true,
    region:"us-east-2",
    accessKeyId : process.env.KEY,
    secretAccessKey : process.env.SECRET

})
app.get('/', async function (req, res) {

    try {

        await Logger.log("Health Check ran", 1, {request : {body : JSON.parse(JSON.stringify(req.body))}});
        res.sendStatus(200);
        
    } catch (error) {
        
        await Logger.error(error.message,3,
            {
                stack : error.stack,
                error : String(error)
            });
        res.send({'error' : error}).sendStatus(500);
    }

})

module.exports.handler = serverless(app);

Log

 await Logger.log("Logging data");
 //or
 await Logger.log("Logging data", 1);
 //or
 await Logger.log("Logging data", 1 , {attribute1 : "1", attribute1 : "2", }); 

Warn

 await Logger.warn("Warning data");
 //or
 await Logger.warn("Warning data", 2);
 //or
 await Logger.warn("Warning data", 2 , {attribute1 : "1", attribute1 : "2", }); 

Error

 await Logger.error("Error data");
 //or
 await Logger.error("Error data", 3);
 //or
 await Logger.error("Error data", 3 , {attribute1 : "1", attribute1 : "2", });  

Short Methods

These shorter methods just swap the argument order for details and severity.

Log

 await Logger.l("Log data");
 //or
 await Logger.l("Log data with object", {attribute1 : "1", attribute1 : "2", });
 //or
 await Logger.l("Log data with object and sev", {attribute1 : "1", attribute1 : "2", }, 1);  

Warn

 await Logger.w("Warn data");
 //or
 await Logger.w("Warn data with object", {attribute1 : "1", attribute1 : "2", });
 //or
 await Logger.w("Warn data with object and sev", {attribute1 : "1", attribute1 : "2", }, 2);  

Error

 await Logger.e("Error data");
 //or
 await Logger.e("Error data with object", {attribute1 : "1", attribute1 : "2", });
 //or
 await Logger.e("Error data with object and sev", {attribute1 : "1", attribute1 : "2", }, 3);