AWS CloudWatch LOGGER
This is simple logger to send logs into AWS CloudWatch Logs stream.
Usage:
const CWLogger = ;const logger = // AWS access accessKeyId: "XXXXXXXXXXXXXXXXXXXX" secretAccessKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" region: "eu-central-1" // Logs destination groupName: "test_group" streamName: "test_stream"; logger;logger;logger;logger; logger;logger;logger;logger;
After that you should see in console:
Text message{ text: 'Supported all data types!' }[ 'Including' ] { _: 'multiple arguments' }false<<category-name>>: Categories supported.<<category-name>>: with<<category-name>>: all 4<<category-name>>: methods
And in AWS console - CloudWatch - Logs:
Options:
Param | Type | Description |
---|---|---|
enabled | {boolean} | Enable sending logs to CloudWatch (default: true ). Leave the option false to don't save logs into CloudWatch Logs |
accessKeyId* | {string} | AWS API key (not required if enabled === false ) |
secretAccessKey* | {string} | AWS API secret (not required if enabled === false ) |
region* | {string} | AWS region (default: eu-central-1 ) (not required if enabled === false ) |
groupName* | {string} | CloudWatch log group name (not required if enabled === false ) |
streamName* | {string} | CloudWatch log stream name in group (not required if enabled === false ) |
consolePrint | {boolean} | Print errors into console (default: true ) |
flushDelay | {number} | Delay in ms. between sending messages (default: 1000 ) |
maxBatchCount | {number} | Max messages to send in butch (default: 5000) |
maxBatchSize | {number} | The maximum batch size (default: 1000000) |
P.S. IAM user should have permissions for actions
["logs:DescribeLogGroups","logs:DescribeLogStreams","logs:PutLogEvents"]
P.P.S. Do not use root user for the security reasons!
INSTALL
npm install aws-cwlogger --save
RUN TESTS
1. Create CloudWatch Logs group and stream:
- Go to "AWS Console" - "Services" - "CloudWatch" - Tab "Logs"
- Create group (ex.
cwlogger-test
) - Go to created group and create stream (ex.
test
) - Go back to tab "Logs" and enabled column "ARN" in table.
- Copy your group's ARN in clipboard, you need it on the next step.
cwlogger-test
)
2. Create AWS IAM user (ex. - Make checked Programmatic access
- Don't check AWS Management Console access
With permission:
Don't forget to replace "Resource" with your ARN.
3. Configure test
cp test/config/example.config.js test/config/config.jsnano test/config/config.js
4. Run tests
npm installnpm test
LICENSE
MIT