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

log4js-appender-cloudwatch

v0.4.2

Published

Log4js cloudwatch appender

Downloads

532

Readme

log4js appender - AWS CloudWatch

This module provides a custom appender for log4js that sends logs to AWS CloudWatch using the AWS v3 SDK.

visual

Installation

npm registry

npm install log4js-appender-cloudwatch

Configuration

Roles

Required

logs:PutLogEvents

To enable the appender to create a group and log stream in AWS, adition roleare required.

logs:PutLogEvents
logs:CreateLogGroup
logs:CreateLogStream
logs:DescribeLogStreams
logs:DescribeLogGroups

Reqired for testing.

To run tests, create .env with AWS access and secret keys.

logs:PutLogEvents
logs:GetLogEvents
{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Action": [
				"logs:PutLogEvents",
				"logs:GetLogEvents"
			],
			"Effect": "Allow",
			"Resource": "*"
		}
	]
}

TypeScript

If you're using TypeScript, importing this library as a side effect will automatically merge the log4js interface Appenders. This merging enables autocomplete for the appenders configuration, providing convenient access to its properties.

import "log4js-appender-cloudwatch";

Example

import log4js from "log4js";

import "log4js-appender-cloudwatch";

log4js.configure({
	appenders: {
		cloudwatch: {
			type: "log4js-appender-cloudwatch",
			accessKeyId: "<secret>",
			secretAccessKey: "<secret>",
			region: "<config>",
			logGroupName: "<config>",
			logStreamName: "<config>",
			batchSize: 10,
			bufferTimeout: 1000, // in ms
		},
	},
	categories: {
		default: {
			level: "debug",
			appenders: [
				"cloudwatch",
			],
		},
	},
});

const log = log4js.getLogger();
// ...

Options

type

Required
Type: log4js-appender-cloudwatch

Type of appender that's loaded from node_modules.

batchSize

Required
Type: number

Maximum number of log events to include in a single batch when sending. Once the batch size is reached, it will be sent to CloudWatch.

bufferTimeout

Required
Type: number

Maximum time (in milliseconds) to wait before sending a batch of logs, regardless of the batch size. If the timeout is reached before the batch size is met, the logs will be sent.

logGroupName (aws)

Required
Type: string

The name of the log group in AWS CloudWatch Logs where your logs are stored.

logStreamName (aws)

Required
Type: string

The name of the log stream within the specified log group where your logs are stored.

region (aws)

Required
Type: string

The AWS region where your log group and log stream are located.

accessKeyId (aws)

Required
Type: string

Your AWS access key ID for authentication.

secretAccessKey (aws)

Required
Type: string

Your AWS secret access key for authentication.

Testing

To test this library during development, you'll need to provide your AWS credentials. These credentials should be stored securely in a .env file located at the root of your project directory.

# .env
accessKeyId="<key>"
secretAccessKey="<key>"

Then, you're ready to run tests:

npm test