Skip to content

Commit

Permalink
Remove legacy stdout logging (#5343)
Browse files Browse the repository at this point in the history
* Remove legacy stdout logging

* Update exports
  • Loading branch information
timleslie authored Apr 1, 2021
1 parent 901817f commit 9557870
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 151 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-fishes-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone-legacy': major
---

Removed logging of errors to stdout using `pino` pending a complete rewrite of this functionality.
55 changes: 5 additions & 50 deletions packages/keystone/lib/Keystone/format-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ const {
formatError: _formatError,
isInstance: isApolloErrorInstance,
} = require('apollo-errors');
const ensureError = require('ensure-error');
const { serializeError } = require('serialize-error');
const StackUtils = require('stack-utils');
const cuid = require('cuid');
const { omit } = require('@keystone-next/utils-legacy');
const { graphqlLogger } = require('./logger');

const stackUtil = new StackUtils({ cwd: process.cwd(), internals: StackUtils.nodeInternals() });

Expand All @@ -22,9 +20,7 @@ const cleanError = maybeError => {

const NestedError = createError('NestedError', {
message: 'Nested errors occurred',
options: {
showPath: true,
},
options: { showPath: true },
});

const safeFormatError = error => {
Expand Down Expand Up @@ -72,59 +68,18 @@ const formatError = error => {
if (originalError && !originalError.path) {
originalError.path = error.path;
}

try {
// For correlating user error reports with logs
error.uid = cuid();

if (isApolloErrorInstance(originalError)) {
// log internalData to stdout but not include it in the formattedError
// TODO: User pino for logging
graphqlLogger.info({
type: 'error',
data: originalError.data,
internalData: originalError.internalData,
});
} else {
const exception = originalError || (error.extensions && error.extensions.exception);
if (exception) {
const pinoError = {
...omit(serializeError(error), ['extensions']),
...omit(exception, ['name', 'model', 'stacktrace']),
stack: stackUtil.clean(exception.stacktrace || exception.stack),
};

if (pinoError.errors) {
pinoError.errors = flattenNestedErrors(exception).map(safeFormatError);
}

graphqlLogger.error(pinoError);
} else {
const errorOutput = serializeError(ensureError(error));
errorOutput.stack = stackUtil.clean(errorOutput.stack);
graphqlLogger.error(errorOutput);
}
}
} catch (formatErrorError) {
// Something went wrong with formatting above, so we log the errors
graphqlLogger.error(serializeError(ensureError(error)));
graphqlLogger.error(serializeError(ensureError(formatErrorError)));

return safeFormatError(error);
}
// For correlating user error reports with logs
error.uid = cuid();

try {
let formattedError;

// Support throwing multiple errors
if (originalError && originalError.errors) {
// Format (aka; serialize) the error
const multipleErrorContainer = new NestedError({
data: {
// Format (aka; serialize) the error
errors: flattenNestedErrors(originalError).map(safeFormatError),
},
data: { errors: flattenNestedErrors(originalError).map(safeFormatError) },
});

formattedError = safeFormatError(multipleErrorContainer);
} else {
formattedError = safeFormatError(error);
Expand Down
6 changes: 0 additions & 6 deletions packages/keystone/lib/Keystone/logger.js

This file was deleted.

16 changes: 3 additions & 13 deletions packages/keystone/lib/ListTypes/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const {
createLazyDeferred,
} = require('@keystone-next/utils-legacy');
const { parseListAccess } = require('@keystone-next/access-control-legacy');
const { graphqlLogger } = require('../Keystone/logger');
const {
preventInvalidUnderscorePrefix,
keyToLabel,
Expand Down Expand Up @@ -317,11 +316,6 @@ module.exports = class List {
}
);
if (!access) {
graphqlLogger.debug(
{ operation, access, gqlName, ...extraInternalData },
'Access statically or implicitly denied'
);
graphqlLogger.info({ operation, gqlName, ...extraInternalData }, 'Access Denied');
// If the client handles errors correctly, it should be able to
// receive partial data (for the fields the user has access to),
// and then an `errors` array of AccessDeniedError's
Expand All @@ -331,9 +325,7 @@ module.exports = class List {
}

async getAccessControlledItem(id, access, { context, operation, gqlName, info }) {
const _throwAccessDenied = msg => {
graphqlLogger.debug({ id, operation, access, gqlName }, msg);
graphqlLogger.info({ id, operation, gqlName }, 'Access Denied');
const _throwAccessDenied = () => {
// If the client handles errors correctly, it should be able to
// receive partial data (for the fields the user has access to),
// and then an `errors` array of AccessDeniedError's
Expand All @@ -351,7 +343,7 @@ module.exports = class List {
// the user has access to. So we have to do a check here to see if the
// ID they're requesting matches that ID.
// Nice side-effect: We can throw without having to ever query the DB.
_throwAccessDenied('Item excluded this id from filters');
_throwAccessDenied();
} else {
// NOTE: The fields will be filtered by the ACL checking in gqlFieldResolvers()
// We only want 1 item, don't make the DB do extra work
Expand All @@ -372,7 +364,7 @@ module.exports = class List {
// that return null do not exist). Similar to how S3 returns 403's
// always instead of ever returning 404's.
// Our version is to always throw if not found.
_throwAccessDenied('Zero items found');
_throwAccessDenied();
}
// Found the item, and it passed the filter test
return item;
Expand Down Expand Up @@ -470,7 +462,6 @@ module.exports = class List {
info
) {
const operation = 'read';
graphqlLogger.debug({ id, operation, type: opToType[operation], gqlName }, 'Start query');

const access = await this.checkListAccess(context, undefined, operation, {
gqlName,
Expand All @@ -484,7 +475,6 @@ module.exports = class List {
info,
});

graphqlLogger.debug({ id, operation, type: opToType[operation], gqlName }, 'End query');
return result;
}

Expand Down
3 changes: 0 additions & 3 deletions packages/keystone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
"cuid": "^2.1.8",
"ensure-error": "^3.0.1",
"express": "^4.17.1",
"express-pino-logger": "^6.0.0",
"falsey": "^1.0.0",
"graphql-type-json": "^0.3.2",
"graphql-upload": "^11.0.0",
"pino": "^6.11.2",
"pluralize": "^8.0.0",
"serialize-error": "^8.0.1",
"stack-utils": "^2.0.3"
Expand Down
80 changes: 1 addition & 79 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3845,11 +3845,6 @@ atob@^2.1.2:
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==

atomic-sleep@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/atomic-sleep/-/atomic-sleep-1.0.0.tgz#eb85b77a601fc932cfe432c5acd364a9e2c9075b"
integrity sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==

autoprefixer@^10.2.5:
version "10.2.5"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.2.5.tgz#096a0337dbc96c0873526d7fef5de4428d05382d"
Expand Down Expand Up @@ -6327,13 +6322,6 @@ expect@^26.6.2:
jest-message-util "^26.6.2"
jest-regex-util "^26.0.0"

express-pino-logger@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/express-pino-logger/-/express-pino-logger-6.0.0.tgz#ed8f71dbbc3c2affbd4104a287f9c2a6a39b435b"
integrity sha512-YjBnalqgsNylRnWEpQGf8YzBP54stpoqX/o+SnpGr04OB7dRIQlsC1qvutFOyRjhLhXIWCe43pYJcjp9zM1Ccg==
dependencies:
pino-http "^5.3.0"

express@^4.17.1:
version "4.17.1"
resolved "https://registry.yarnpkg.com/express/-/express-4.17.1.tgz#4491fc38605cf51f8629d39c2b5d026f98a4c134"
Expand Down Expand Up @@ -6459,11 +6447,6 @@ facepaint@^1.2.1:
resolved "https://registry.yarnpkg.com/facepaint/-/facepaint-1.2.1.tgz#89929e601b15227278c53c516f764fc462b09c33"
integrity sha512-oNvBekbhsm/0PNSOWca5raHNAi6dG960Bx6LJgxDPNF59WpuspgQ17bN5MKwOr7JcFdQYc7StW3VZ28DBZLavQ==

"falsey@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/falsey/-/falsey-1.0.0.tgz#71bdd775c24edad9f2f5c015ce8be24400bb5d7d"
integrity sha512-zMDNZ/Ipd8MY0+346CPvhzP1AsiVyNfTOayJza4reAIWf72xbkuFUDcJNxSAsQE1b9Bu0wijKb8Ngnh/a7fI5w==

fast-deep-equal@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
Expand Down Expand Up @@ -6508,23 +6491,11 @@ fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6:
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=

fast-redact@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/fast-redact/-/fast-redact-3.0.0.tgz#ac2f9e36c9f4976f5db9fb18c6ffbaf308cf316d"
integrity sha512-a/S/Hp6aoIjx7EmugtzLqXmcNsyFszqbt6qQ99BdG61QjBZF6shNis0BYR6TsZOQ1twYc0FN2Xdhwwbv6+KD0w==

fast-safe-stringify@^2.0.7:
version "2.0.7"
resolved "https://registry.yarnpkg.com/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz#124aa885899261f68aedb42a7c080de9da608743"
integrity sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA==

fast-url-parser@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/fast-url-parser/-/fast-url-parser-1.1.3.tgz#f4af3ea9f34d8a271cf58ad2b3759f431f0b318d"
integrity sha1-9K8+qfNNiicc9YrSs3WfQx8LMY0=
dependencies:
punycode "^1.3.2"

[email protected]:
version "0.2.1"
resolved "https://registry.yarnpkg.com/fast-write-atomic/-/fast-write-atomic-0.2.1.tgz#7ee8ef0ce3c1f531043c09ae8e5143361ab17ede"
Expand Down Expand Up @@ -6702,11 +6673,6 @@ flat-cache@^3.0.4:
flatted "^3.1.0"
rimraf "^3.0.2"

flatstr@^1.0.12:
version "1.0.12"
resolved "https://registry.yarnpkg.com/flatstr/-/flatstr-1.0.12.tgz#c2ba6a08173edbb6c9640e3055b95e287ceb5931"
integrity sha512-4zPxDyhCyiN2wIAtSLI6gc82/EjqZc1onI4Mz/l0pWrAlsSfYH/2ZIcU+e3oA2wDwbzIWNKwa23F8rh6+DRWkw==

flatted@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138"
Expand Down Expand Up @@ -10608,37 +10574,6 @@ pify@^4.0.1:
resolved "https://registry.yarnpkg.com/pify/-/pify-4.0.1.tgz#4b2cd25c50d598735c50292224fd8c6df41e3231"
integrity sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==

pino-http@^5.3.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/pino-http/-/pino-http-5.5.0.tgz#b91e02714cc40b13fc3d82222fc1a96f0c99d6ea"
integrity sha512-ZXhWeYhUisf9oZdS54XaBTrNVzZ7p61/sw0RpwCdU1vI/qdGWvSG4QUA5qU5Y5ya47ch3kM3HTcZf/QB5SCtNw==
dependencies:
fast-url-parser "^1.1.3"
pino "^6.0.0"
pino-std-serializers "^2.4.0"

pino-std-serializers@^2.4.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/pino-std-serializers/-/pino-std-serializers-2.5.0.tgz#40ead781c65a0ce7ecd9c1c33f409d31fe712315"
integrity sha512-wXqbqSrIhE58TdrxxlfLwU9eDhrzppQDvGhBEr1gYbzzM4KKo3Y63gSjiDXRKLVS2UOXdPNR2v+KnQgNrs+xUg==

pino-std-serializers@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/pino-std-serializers/-/pino-std-serializers-3.2.0.tgz#b56487c402d882eb96cd67c257868016b61ad671"
integrity sha512-EqX4pwDPrt3MuOAAUBMU0Tk5kR/YcCM5fNPEzgCO2zJ5HfX0vbiH9HbJglnyeQsN96Kznae6MWD47pZB5avTrg==

pino@^6.0.0, pino@^6.11.2:
version "6.11.2"
resolved "https://registry.yarnpkg.com/pino/-/pino-6.11.2.tgz#2f3d119c526651aab4ec3d280844785d52d0b690"
integrity sha512-bmzxwbrIPxQUlAuMkF4PWVErUGERU4z37HazlhflKFg08crsNE3fACGN6gPwg5xtKOK47Ux5cZm8YCuLV4wWJg==
dependencies:
fast-redact "^3.0.0"
fast-safe-stringify "^2.0.7"
flatstr "^1.0.12"
pino-std-serializers "^3.1.0"
quick-format-unescaped "4.0.1"
sonic-boom "^1.0.2"

pirates@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.1.tgz#643a92caf894566f91b2b986d2c66950a8e2fb87"
Expand Down Expand Up @@ -10979,7 +10914,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d"
integrity sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0=

punycode@^1.2.4, punycode@^1.3.2:
punycode@^1.2.4:
version "1.4.1"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"
integrity sha1-wNWmOycYgArY4esPpSachN1BhF4=
Expand Down Expand Up @@ -11046,11 +10981,6 @@ queue-microtask@^1.2.2:
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
integrity sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==

[email protected]:
version "4.0.1"
resolved "https://registry.yarnpkg.com/quick-format-unescaped/-/quick-format-unescaped-4.0.1.tgz#437a5ea1a0b61deb7605f8ab6a8fd3858dbeb701"
integrity sha512-RyYpQ6Q5/drsJyOhrWHYMWTedvjTIat+FTwv0K4yoUxzvekw2aRHMQJLlnvt8UantkZg2++bEzD9EdxXqkWf4A==

quick-lru@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-1.1.0.tgz#4360b17c61136ad38078397ff11416e186dcfbb8"
Expand Down Expand Up @@ -12234,14 +12164,6 @@ snapdragon@^0.8.1:
source-map-resolve "^0.5.0"
use "^3.1.0"

sonic-boom@^1.0.2:
version "1.4.0"
resolved "https://registry.yarnpkg.com/sonic-boom/-/sonic-boom-1.4.0.tgz#d6d35196c32609b46193145afc1174a8c692d21e"
integrity sha512-1xUAszhQBOrjk7uisbStQZYkZxD3vkYlCUw5qzOblWQ1ILN5v0dVPAs+QPgszzoPmbdWx6jyT9XiLJ95JdlLiQ==
dependencies:
atomic-sleep "^1.0.0"
flatstr "^1.0.12"

source-map-resolve@^0.5.0:
version "0.5.3"
resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.5.3.tgz#190866bece7553e1f8f267a2ee82c606b5509a1a"
Expand Down

1 comment on commit 9557870

@vercel
Copy link

@vercel vercel bot commented on 9557870 Apr 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.