winston-cloudwatch
winston-cloudwatch copied to clipboard
Improve formatting for filtering
You can filter CloudWatch logs, but only easily if they are formatted a certain way.
Currently, this is the formatting code:
return _.isEmpty(log.meta) ?
[ log.level, log.msg ].join(' - ') :
[ log.level, log.msg, stringify(log.meta) ].join(' - ');
However, according to Amazon, pieces must be space-delimited. It also states The characters between a pair of square brackets [] or two double quotes ("") are treated as a single field.
Would it be best to delimit pieces with spaces, wrapping most with [] or ""?
Example:
Current: level - multi word message - meta
I believe Amazon sees this as the following pieces:
- level
- -
- multi
- word
- message
- -
- meta
I think if we instead wrapped pieces like this...
level [multi word message] [meta] Amazon would see:
- level
- multi word message
- meta
If we want to do this, here is a rough patch:
var result = log.level + ' [' + log.msg + ']';
if (!_.isEmpty(log.meta)) result += ' [' + stringify(log.meta) + ']';
return result;
Thanks @westy92 I am currently working on the other issues, but if you think it would help you and others feel free to submit a PR.