Skip to content

Commit

Permalink
fix: removed meta.args due to circular reference issues (e.g. in mong…
Browse files Browse the repository at this point in the history
…oose)
  • Loading branch information
titanism committed Nov 20, 2022
1 parent c2bd2a4 commit 52870ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ Axe will automatically add the following metadata and information to the `meta`

| Property | Type | Description |
| ------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `meta.args` | Array | The original arguments passed to the logger method when invoked. **Note that this is hidden by default via `meta.omittedFields` option**. |
| `meta.level` | String | The log level invoked (e.g. `"info"`). |
| `meta.err` | Object | Parsed error information using [parse-err][]. |
| `meta.original_err` | Object | If and only if `meta.err` already existed, this field is preserved as `meta.original_err` on the metadata object. |
Expand All @@ -315,7 +314,7 @@ Axe will automatically add the following metadata and information to the `meta`
| `meta.app.os` | Object | Node [os](https://nodejs.org/api/os.html) information. |
| `meta.app.worker_threads` | Object | Node [worker_threads](https://nodejs.org/api/worker_threads.html) information. |

:warning: **Note that by default,** **<u>Axe will not output this additional information for you</u>** (since we set the `meta.omittedFields` option to `[ 'level', 'err', 'app', 'args' ]` by default).
:warning: **Note that by default,** **<u>Axe will not output this additional information for you</u>** (since we set the `meta.omittedFields` option to `[ 'level', 'err', 'app' ]` by default).

Axe will omit from metadata all properties via the default Array from `meta.omittedFields` option (see [Options](#options) below for more insight).

Expand All @@ -329,12 +328,11 @@ const Axe = require('axe');
const logger = new Axe({
meta: {
omittedFields: []
// NOTE: the default is `[ 'level', 'err', 'app', 'args' ]`
// NOTE: the default is `[ 'level', 'err', 'app' ]`
}
});

// hello world {
// args: [ 'info', 'hello world' ],
// level: 'info',
// app: {
// name: 'axe',
Expand Down Expand Up @@ -405,7 +403,7 @@ See [Browser](#browser-1) usage below for more information.
| `meta` | Object | See below | Stores all meta config information (see the following nested properties below). | |
| `meta.show` | Boolean | `true` | Attempts to parse a boolean value from `process.env.AXE_SHOW_META` – meaning you can pass a flag `AXE_SHOW_META=true node app.js` when needed for debugging), whether or not to output metadata to logger methods. If set to `false`, then fields will not be omitted nor picked; the entire meta object will be hidden from logger output. | |
| `meta.remappedFields` | Object | `{}` | Attempts to parse an Object mapping from `process.env.AXE_REMAPPED_META_FIELDS` (`,` and `:` delimited, e.g. `REMAPPED_META_FIELDS=foo:bar,beep.boop:beepBoop` to remap `meta.foo` to `meta.bar` and `meta.beep.boop` to `meta.beepBoop`). Note that this will clean up empty objects by default unless you set the option `meta.cleanupRemapping` to `false`). Supports dot-notation. | |
| `meta.omittedFields` | Array | `['level','err','app', 'args']` in Node environments and `[]` in Browser environments | Attempts to parse an array value from `process.env.AXE_OMIT_META_FIELDS` (`,` delimited) - meaning you can pass a flag `OMIT_META_FIELDS=user,id node app.js`), determining which fields to omit in the metadata passed to logger methods. Supports dot-notation. | |
| `meta.omittedFields` | Array | `['level','err','app']` in Node environments and `[]` in Browser environments | Attempts to parse an array value from `process.env.AXE_OMIT_META_FIELDS` (`,` delimited) - meaning you can pass a flag `OMIT_META_FIELDS=user,id node app.js`), determining which fields to omit in the metadata passed to logger methods. Supports dot-notation. | |
| `meta.pickedFields` | Array | `[]` | Attempts to parse an array value from `process.env.AXE_PICK_META_FIELDS` (`,` delimited) - meaning you can pass a flag, e.g. `PICK_META_FIELDS=request.headers,response.headers node app.js` which would pick from `meta.request` and `meta.response` *only* `meta.request.headers` and `meta.response.headers`), **This takes precedence after fields are omitted, which means this acts as a whitelist.** Supports dot-notation. | |
| `meta.cleanupRemapping` | Boolean | `true` | Whether or not to cleanup empty objects after remapping operations are completed) | |
| `silent` | Boolean | `false` | Whether or not to invoke logger methods. Pre and post hooks will still run even if this option is set to `false`. | |
Expand Down Expand Up @@ -676,7 +674,7 @@ If you would like to omit fields, such as `response.headers` from a response, so
```js
const logger = new Axe({
meta: {
omittedFields: ['level', 'err', 'app', 'args', 'response.headers']
omittedFields: ['level', 'err', 'app', 'response.headers']
}
});
Expand Down
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,13 @@ class Axe {
if (!isString(message)) message = err.message;
}

//
// NOTE: this was removed in v10.2.3 due to circular reference issues
// (the workaround would involve safeStringify and then JSON.parse which would be perf bloat)
// (there still might be another workaround or perhaps we don't add all the args here except additional)
//
// Set `args` prop with original arguments passed
meta.args = originalArgs;
// meta.args = originalArgs;

// Set default level on meta
meta.level = level;
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/before-each.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = function (logger) {
remappedFields: {
'remap.field': 'remappedField'
},
omittedFields: ['level', 'err', 'app', 'args', 'request', 'beep'],
omittedFields: ['level', 'err', 'app', 'request', 'beep'],
pickedFields: ['request.headers', 'foo.bar']
},
hooks: {
Expand Down

0 comments on commit 52870ac

Please sign in to comment.