Skip to content

Commit

Permalink
Fix #46 and #49. Upgrade winston-cloudwatch.
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-guy committed Mar 20, 2022
1 parent 1388ccd commit d398d9c
Show file tree
Hide file tree
Showing 23 changed files with 236 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
lts/fermium
lts/erbium

4 changes: 2 additions & 2 deletions GeneratorLogger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-param-reassign */
const { nanoid } = require('nanoid');
const { ulid } = require('ulid');

/**
* @description Logs the start of a generator and returns an object for logging the progress, end, and error of it
Expand All @@ -26,7 +26,7 @@ class GeneratorLogger {
* b) taskId
*/
static begin(logger, beginMessage, endMessage, errorMessage) {
const taskId = nanoid();
const taskId = ulid();
logger = logger.child(taskId);
logger.log('begin', beginMessage);

Expand Down
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

## Requirements

- NodeJS 8 and higher
If you are using CloudWatch logs as a transport, NodeJS 12 (LTS/erbium) or higher is required. Otherwise, any LTS version is sufficent.

## Installation

Expand All @@ -26,9 +26,7 @@ This package extends Winston3 with additional features such as tag-based filteri

1. HAPI-style tags: Log entries can be filtered by tags on a per-transport basis
2. Redaction of specific object keys. Redaction can be enabled and disabled via tags.
3. Safely logs large objects and arrays - even those with circular references
3.1. Embedded Error objects are logged separately (e.g., in the 'cause' and 'error' properties), grouping multiple
log entries via uuid
3. Safely logs large objects and arrays - even those with circular references 3.1. Embedded Error objects are logged separately (e.g., in the 'cause' and 'error' properties), grouping multiple log entries via a unique identifier
4. Promotes object properties to a configurable subset of 'meta' properties
5. Reliable flushing
6. Does not interfere with other code that uses Winston
Expand Down Expand Up @@ -269,8 +267,7 @@ message and 'context' are shallow copied and combined into a new object called '

If both.error is truthy and both.message is falsey, both.message is set to `both.error.asString()`.

Error objects that are discovered in the top-level keys of both are logged separately, in a parent-child fashion, and recursively. This allows the stack trace and other details of every Error in a chain to be logged using applicable redaction rules. Each log entry contains the same groupId meta value. The data properties of parent entries contain the result of converting Error strings. For example, if both.error is an Error object, data.error will contain the Error object converted to a string. This process is performed recursively. Circular references are handled gracefully. The depth meta key contains a number, starting from 1, that indicates the recursion depth from both. The maximum recursion depth is specified via the 'maxErrorDepth' options setting. The maximum number of errors to log is
specified via the 'maxErrors' options setting.
Error objects that are discovered in the top-level keys of both are logged separately, in a parent-child fashion, and recursively. This allows the stack trace and other details of every Error in a chain to be logged using applicable redaction rules. Each log entry contains the same groupId meta value. The data properties of parent entries contain the result of converting Error strings. For example, if both.error is an Error object, data.error will contain the Error object converted to a string. This process is performed recursively. Circular references are handled gracefully. The depth meta key contains a number, starting from 1, that indicates the recursion depth from both. The maximum recursion depth is specified via the 'maxErrorDepth' options setting. The maximum number of errors to log is specified via the 'maxErrors' options setting.

The following example produces three three log entries. error3 will be logged first, followed by error2, followed by error1. error1's corresponding log entry contains a data.cause key with a string value of 'Error: error2.'

Expand Down Expand Up @@ -360,7 +357,7 @@ If an AWS region is not specified, the environment variables are used in the fol

## Begin/End/Error Utility Classes

Utility functions are provided for logging begin and end messages for common operations (database, http, etc.). Begin log entries are tagged with 'begin.' End log entries are tagged with 'end.' The operationId property is added to both log entries with the same uuid generated for the operation. If an exception is thrown, an error is logged. These functions are implemented as static methods.
Utility functions are provided for logging begin and end messages for common operations (database, http, etc.). Begin log entries are tagged with 'begin.' End log entries are tagged with 'end.' The operationId property is added to both log entries with the same unique identifier generated for the operation. If an exception is thrown, an error is logged. These functions are implemented as static methods.

The following classes are available:

Expand Down
4 changes: 2 additions & 2 deletions TaskLogger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-param-reassign */
const { nanoid } = require('nanoid');
const { ulid } = require('ulid');

/**
* @description Logs the start and the completion or error of a task whether synchronous or asynchronous
Expand Down Expand Up @@ -44,7 +44,7 @@ class TaskLogger {
* @returns {Promise} Resolves to the value returned or rejects using exception thrown by the task
*/
static async execute(logger, task, beginMessage, endMessage, errorMessage, errorHandler) {
const taskId = nanoid();
const taskId = ulid();
logger = logger.child(taskId);
logger.log('begin', beginMessage);

Expand Down
2 changes: 1 addition & 1 deletion docs/Defaults.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h1 class="page-title">Defaults.js</h1>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> on Wed Dec 01 2021 10:51:17 GMT-0800 (Pacific Standard Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sun Mar 20 2022 12:41:20 GMT-0700 (Pacific Daylight Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/GeneratorLogger.html
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> on Wed Dec 01 2021 10:51:17 GMT-0800 (Pacific Standard Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sun Mar 20 2022 12:41:20 GMT-0700 (Pacific Daylight Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
6 changes: 3 additions & 3 deletions docs/GeneratorLogger.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h1 class="page-title">GeneratorLogger.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/* eslint-disable no-param-reassign */
const { nanoid } = require('nanoid');
const { ulid } = require('ulid');

/**
* @description Logs the start of a generator and returns an object for logging the progress, end, and error of it
Expand All @@ -67,7 +67,7 @@ <h1 class="page-title">GeneratorLogger.js</h1>
* b) taskId
*/
static begin(logger, beginMessage, endMessage, errorMessage) {
const taskId = nanoid();
const taskId = ulid();
logger = logger.child(taskId);
logger.log('begin', beginMessage);

Expand All @@ -93,7 +93,7 @@ <h1 class="page-title">GeneratorLogger.js</h1>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> on Wed Dec 01 2021 10:51:17 GMT-0800 (Pacific Standard Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sun Mar 20 2022 12:41:20 GMT-0700 (Pacific Daylight Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
48 changes: 24 additions & 24 deletions docs/Loggers.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ <h4 class="name" id="Loggers"><span class="type-signature"></span>new Loggers<sp

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line95">line 95</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line97">line 97</a>
</li></ul></dd>


Expand Down Expand Up @@ -298,7 +298,7 @@ <h4 class="name" id=".defaultLevels"><span class="type-signature">(static) </spa

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line2436">line 2436</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line2438">line 2438</a>
</li></ul></dd>


Expand Down Expand Up @@ -364,7 +364,7 @@ <h4 class="name" id=".defaultMetaKeys"><span class="type-signature">(static) </s

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line2427">line 2427</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line2429">line 2429</a>
</li></ul></dd>


Expand Down Expand Up @@ -424,7 +424,7 @@ <h4 class="name" id="loggers"><span class="type-signature"></span>loggers<span c

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1610">line 1610</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1603">line 1603</a>
</li></ul></dd>


Expand Down Expand Up @@ -484,7 +484,7 @@ <h4 class="name" id="parent"><span class="type-signature"></span>parent<span cla

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1617">line 1617</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1610">line 1610</a>
</li></ul></dd>


Expand Down Expand Up @@ -548,7 +548,7 @@ <h4 class="name" id="ready"><span class="type-signature"></span>ready<span class

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1625">line 1625</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1618">line 1618</a>
</li></ul></dd>


Expand Down Expand Up @@ -612,7 +612,7 @@ <h4 class="name" id="winstonLevels"><span class="type-signature"></span>winstonL

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line214">line 214</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line216">line 216</a>
</li></ul></dd>


Expand Down Expand Up @@ -696,7 +696,7 @@ <h4 class="name" id="category"><span class="type-signature"></span>category<span

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line751">line 751</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line754">line 754</a>
</li></ul></dd>


Expand Down Expand Up @@ -884,7 +884,7 @@ <h4 class="name" id="child"><span class="type-signature"></span>child<span class

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1586">line 1586</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1579">line 1579</a>
</li></ul></dd>


Expand Down Expand Up @@ -1124,7 +1124,7 @@ <h4 class="name" id="context"><span class="type-signature"></span>context<span c

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line386">line 386</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line388">line 388</a>
</li></ul></dd>


Expand Down Expand Up @@ -1335,7 +1335,7 @@ <h4 class="name" id="default"><span class="type-signature"></span>default<span c

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line2378">line 2378</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line2380">line 2380</a>
</li></ul></dd>


Expand Down Expand Up @@ -1443,7 +1443,7 @@ <h4 class="name" id="flush"><span class="type-signature"></span>flush<span class

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1139">line 1139</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1142">line 1142</a>
</li></ul></dd>


Expand Down Expand Up @@ -1547,7 +1547,7 @@ <h4 class="name" id="flushCloudWatchTransports"><span class="type-signature">(as

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1102">line 1102</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1105">line 1105</a>
</li></ul></dd>


Expand Down Expand Up @@ -1651,7 +1651,7 @@ <h4 class="name" id="isLevelEnabled"><span class="type-signature"></span>isLevel

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1769">line 1769</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1762">line 1762</a>
</li></ul></dd>


Expand Down Expand Up @@ -1860,7 +1860,7 @@ <h4 class="name" id="levelEnabled"><span class="type-signature"></span>levelEnab

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1986">line 1986</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1979">line 1979</a>
</li></ul></dd>


Expand Down Expand Up @@ -1951,7 +1951,7 @@ <h4 class="name" id="log"><span class="type-signature"></span>log<span class="si

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line2399">line 2399</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line2401">line 2401</a>
</li></ul></dd>


Expand Down Expand Up @@ -2231,7 +2231,7 @@ <h4 class="name" id="logger"><span class="type-signature"></span>logger<span cla

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1555">line 1555</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1548">line 1548</a>
</li></ul></dd>


Expand Down Expand Up @@ -2441,7 +2441,7 @@ <h4 class="name" id="restart"><span class="type-signature">(async) </span>restar

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1235">line 1235</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1228">line 1228</a>
</li></ul></dd>


Expand Down Expand Up @@ -2545,7 +2545,7 @@ <h4 class="name" id="stack"><span class="type-signature"></span>stack<span class

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1596">line 1596</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1589">line 1589</a>
</li></ul></dd>


Expand Down Expand Up @@ -2713,7 +2713,7 @@ <h4 class="name" id="start"><span class="type-signature"></span>start<span class

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line627">line 627</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line630">line 630</a>
</li></ul></dd>


Expand Down Expand Up @@ -2796,7 +2796,7 @@ <h4 class="name" id="stop"><span class="type-signature">(async) </span>stop<span

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1258">line 1258</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1251">line 1251</a>
</li></ul></dd>


Expand Down Expand Up @@ -2918,7 +2918,7 @@ <h4 class="name" id="tags"><span class="type-signature"></span>tags<span class="

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line321">line 321</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line323">line 323</a>
</li></ul></dd>


Expand Down Expand Up @@ -3127,7 +3127,7 @@ <h4 class="name" id="winstonLogger"><span class="type-signature"></span>winstonL

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1528">line 1528</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1521">line 1521</a>
</li></ul></dd>


Expand Down Expand Up @@ -3268,7 +3268,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> on Wed Dec 01 2021 10:51:17 GMT-0800 (Pacific Standard Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sun Mar 20 2022 12:41:20 GMT-0700 (Pacific Daylight Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/MySqlLogger.html
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> on Wed Dec 01 2021 10:51:17 GMT-0800 (Pacific Standard Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sun Mar 20 2022 12:41:20 GMT-0700 (Pacific Daylight Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/MySqlLogger.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ <h1 class="page-title">MySqlLogger.js</h1>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> on Wed Dec 01 2021 10:51:17 GMT-0800 (Pacific Standard Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sun Mar 20 2022 12:41:20 GMT-0700 (Pacific Daylight Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/RequestLogger.html
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> on Wed Dec 01 2021 10:51:17 GMT-0800 (Pacific Standard Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sun Mar 20 2022 12:41:20 GMT-0700 (Pacific Daylight Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/RequestLogger.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ <h1 class="page-title">RequestLogger.js</h1>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> on Wed Dec 01 2021 10:51:17 GMT-0800 (Pacific Standard Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sun Mar 20 2022 12:41:20 GMT-0700 (Pacific Daylight Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Stack.html
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> on Wed Dec 01 2021 10:51:17 GMT-0800 (Pacific Standard Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sun Mar 20 2022 12:41:20 GMT-0700 (Pacific Daylight Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Stack.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ <h1 class="page-title">Stack.js</h1>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> on Wed Dec 01 2021 10:51:17 GMT-0800 (Pacific Standard Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sun Mar 20 2022 12:41:20 GMT-0700 (Pacific Daylight Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down

0 comments on commit d398d9c

Please sign in to comment.