Gathering detailed insights and metrics for log4js-cloudwatch-appender
Gathering detailed insights and metrics for log4js-cloudwatch-appender
Gathering detailed insights and metrics for log4js-cloudwatch-appender
Gathering detailed insights and metrics for log4js-cloudwatch-appender
log4js simple appender for writing logs to AWS CloudWatch
npm install log4js-cloudwatch-appender
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (93.4%)
Makefile (6.6%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
GPL-3.0 License
7 Stars
21 Commits
2 Forks
3 Watchers
2 Branches
2 Contributors
Updated on Feb 14, 2024
Latest Version
1.1.0
Package Id
log4js-cloudwatch-appender@1.1.0
Size
15.21 kB
NPM Version
3.10.10
Node Version
6.10.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
Simple appender for log4js to submit logs to AWS cloudwatch based on the lawgs module.
This module is installed via npm:
npm install --save log4js-cloudwatch-appender
Add aws appender to the log4js config file:
1const config = { 2 appenders: { 3 aws: { 4 type: "log4js-cloudwatch-appender", 5 accessKeyId: '<accessKeyId>', 6 secretAccessKey: '<secretAccessKey>', 7 region: 'eu-central-1', 8 logGroup: 'prod', 9 logStream: 'apps', 10 layout: '<custom layout object>', 11 lawgsConfig: '<optional alwgs config object>' 12 } 13 }, 14 categories: { 15 default: {appenders: ['aws'], level: 'info'} 16 } 17}
This will cause logs to be sent to AWS CloudWatch with the specified group and stream.
If you are using roles, you will need the following roles:
region
- The CloudWatch regionlogGroup
- The log group to send the metrics tologStream
- The log stream of the group to send the metrics toaccessKeyId
- Optional if credentials are set in ~/.aws/credentials
secretAccessKey
- Optional if credentials are set in ~/.aws/credentials
layout
- Custom layout. See suggested layoutlawgsConfig
- Optional vonfig object for lawgs:
showDebugLogs
- Show debug logs. Default: false.uploadMaxTimer
- After this ms timeout, flush to server. Default: 5000.uploadBatchSize
- After this amount of logs, flush to server. Default: 500.Logs are easier to query whn they are formatted as json. Following is a suggested json layout to set for this appender. The logging style should be:
1const uuid = require('node-uuid'); 2const corr = uuid.v4(); 3const logger = logFactory.getLogger('category'); 4 5logger.info(corr, 'methodName()','part1','part2');
Which will output:
1{ 2 "timestamp": "2017-06-10T11:55:38.251Z", 3 "corr": "2e2c99aa-7eee-4fd2-ae36-cd9dc9533816", 4 "app": "<appName>", 5 "host": "<ip>", 6 "pid": 24532, 7 "level": "INFO", 8 "category": "category", 9 "method": "methodName()", 10 "message": "part1 part2" 11}
The layout:
1const util = require('util'); 2const _ = require('underscore'); 3 4let processName = path.basename(process.argv[1]); 5processName = processName.substring(0, processName.length - 3); 6 7const publicIp = require('public-ip').v4; 8let ip = ''; 9publicIp() 10 .then(function (_ip) { 11 ip = _ip; 12 }) 13 .catch(function (e) { 14 console.log(e); 15 ip = 'unknown'; 16 }); 17 18const jsonLayout = { 19 "type": "pattern", 20 "pattern": '{"timestamp": "%d{yyyy-MM-ddThh:mm:ss.SSSZ}", "app": "' + processName + '", "ip": "%x{my_ip}", "host": "%h", "pid": %z, "level": "%p", "category": "%c"%x{corr}%x{method}, "message": "%x{message}"}', 21 "tokens": { 22 "my_ip": function () { 23 return ip; 24 }, 25 "corr": function (logEvent) { 26 logEvent.__data__ = _.map(logEvent.data, _.clone); 27 if (logEvent.__data__) { 28 let corr = logEvent.__data__[0]; 29 if (Array.isArray(corr) && corr.length === 2) { 30 corr = corr[0]; 31 if (typeof corr === 'string' && corr.length === 36 && corr.split("-").length === 5) { 32 logEvent.__data__[0] = logEvent.__data__[0][1]; 33 return ', "corr": "' + corr + '"'; 34 } 35 } 36 if (logEvent.__data__.length > 1 && corr && typeof corr === 'string' && corr.length === 36 && corr.split("-").length === 5) { 37 logEvent.__data__.shift(); 38 return ', "corr": "' + corr + '"'; 39 } 40 } 41 return ''; 42 }, 43 "method": function (logEvent) { 44 if (logEvent.__data__) { 45 const method = logEvent.__data__[0]; 46 if (logEvent.__data__.length > 1 && method && typeof method === 'string' && method.indexOf("()", method.length - 2) !== -1) { 47 logEvent.__data__.shift(); 48 return ', "method": "' + method + '"'; 49 } 50 } 51 return ''; 52 }, 53 "message": function (logEvent) { 54 if (logEvent.__data__) { 55 let data = logEvent.__data__; 56 data = util.format.apply(util, wrapErrorsWithInspect(data)); 57 data = escapedStringify(data); 58 logEvent.__data__ = undefined; 59 return data; 60 } 61 return ''; 62 } 63 } 64}; 65 66function wrapErrorsWithInspect(items) { 67 return items.map(function (item) { 68 if ((item instanceof Error) && item.stack) { 69 return { 70 inspect: function () { 71 return util.format(item) + '\n' + item.stack; 72 } 73 }; 74 } else { 75 return item; 76 } 77 }); 78} 79 80function escapedStringify(json) { 81 return json 82 .replace(/[\\]/g, '\\\\') 83 .replace(/[\"]/g, '\\\"') 84 .replace(/[\/]/g, '\\/') 85 .replace(/[\b]/g, '\\b') 86 .replace(/[\f]/g, '\\f') 87 .replace(/[\n]/g, '\\n') 88 .replace(/[\r]/g, '\\r') 89 .replace(/[\t]/g, '\\t'); 90}
Please make all pull requests to the master
branch and ensure tests pass
locally.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 1/21 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More