molindo-node-logger
Advanced tools
Comparing version 1.2.0 to 1.3.0
# Changelog | ||
## 1.3.0 | ||
Limit the size of logged `variables` for `meta.graphql` in the middleware logger | ||
via `maxGraphQLVariablesLength`. It's possible that `variables` is a big object that could bloat the payload. | ||
## 1.2.0 | ||
@@ -4,0 +9,0 @@ |
@@ -28,3 +28,3 @@ 'use strict'; | ||
exports.default = ({ logger }) => { | ||
exports.default = ({ logger, maxGraphQLVariablesLength = 512 }) => { | ||
const router = new _express.Router(); | ||
@@ -48,5 +48,24 @@ return router.use(_bodyParser2.default.json(), _expressWinston2.default.logger({ | ||
if (req.method === 'POST' && req.body && req.body.operationName) { | ||
let variables = undefined; | ||
if (maxGraphQLVariablesLength === -1) { | ||
variables = req.body.variables; | ||
} else if (maxGraphQLVariablesLength === 0) { | ||
// Keep variables undefined | ||
variables = undefined; | ||
} else if (maxGraphQLVariablesLength > 0) { | ||
const stringifiedVariables = JSON.stringify(req.body.variables); | ||
const isTooLarge = stringifiedVariables.length > maxGraphQLVariablesLength; | ||
if (isTooLarge) { | ||
variables = `${stringifiedVariables.substring(0, maxGraphQLVariablesLength)} […] max payload length reached (${maxGraphQLVariablesLength} chars)`; | ||
} else { | ||
variables = req.body.variables; | ||
} | ||
} | ||
meta.graphql = { | ||
operationName: req.body.operationName, | ||
variables: req.body.variables | ||
variables | ||
}; | ||
@@ -53,0 +72,0 @@ } |
{ | ||
"name": "molindo-node-logger", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "A node.js logger that integrates well with the Molindo infrastructure.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -42,3 +42,5 @@ # molindo-node-logger | ||
If you're running an express server, you can register the logger middleware to log HTTP requests. | ||
If you're running an express server, you can register the logger middleware to | ||
log HTTP requests. GraphQL requests get automatically detected and attached as | ||
`meta.graphql`, with properties `operationName` and the respective `variables`. | ||
@@ -54,1 +56,10 @@ ```js | ||
``` | ||
The size of `meta.graphql.variables` can sometimes grow too large to log | ||
effectively. To manage this, the `createLoggerMiddleware()` function provides a configurable parameter: | ||
`maxGraphQLVariablesLength`. | ||
#### Configuration of `maxGraphQLVariablesLength` | ||
* Set `maxGraphQLVariablesLength` (default: 512), to set the maximum size of the `meta.graphql.variables` payload to be logged. | ||
* Set `maxGraphQLVariablesLength` to `0` to completely turn off logging for `meta.graphql.variables`. | ||
* Set `maxGraphQLVariablesLength` to `-1` to include the complete `meta.graphql.variables` payload without size restrictions. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12831
220
64