molindo-node-logger
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -225,3 +225,3 @@ Object.defineProperty(exports, '__esModule', { value: true }); | ||
const MASKED_HEADER_VALUE = '*****'; | ||
var createLoggerMiddleware = (({ logger })=>{ | ||
var createLoggerMiddleware = (({ logger, maxGraphQLVariablesLength = 512 })=>{ | ||
const router = new express.Router(); | ||
@@ -244,5 +244,20 @@ return router.use(bodyParser__default.default.json(), expressWinston__default.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 | ||
}; | ||
@@ -249,0 +264,0 @@ } |
{ | ||
"name": "molindo-node-logger", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "A node.js logger that integrates well with the Molindo infrastructure.", | ||
@@ -5,0 +5,0 @@ "main": "dist/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. |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
23784
568
64
0
4