mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
feat(api): use pino-pretty for dev logging (#49713)
feat: use pino-pretty for dev logging
This commit is contained in:
committed by
GitHub
parent
7d01522c0d
commit
17d7fc0af5
+17
-2
@@ -12,6 +12,7 @@ import { testRoutes } from './routes/test';
|
||||
import { auth0Routes } from './routes/auth0';
|
||||
import { testValidatedRoutes } from './routes/validation-test';
|
||||
import { testMiddleware } from './middleware';
|
||||
import prismaPlugin from './db/prisma';
|
||||
|
||||
import {
|
||||
AUTH0_AUDIENCE,
|
||||
@@ -22,10 +23,24 @@ import {
|
||||
SESSION_SECRET
|
||||
} from './utils/env';
|
||||
|
||||
import prismaPlugin from './db/prisma';
|
||||
const envToLogger = {
|
||||
development: {
|
||||
transport: {
|
||||
target: 'pino-pretty',
|
||||
options: {
|
||||
translateTime: 'HH:MM:ss Z',
|
||||
ignore: 'pid,hostname'
|
||||
}
|
||||
},
|
||||
level: 'debug'
|
||||
},
|
||||
// TODO: is this the right level for production or should we use 'error'?
|
||||
production: { level: 'fatal' },
|
||||
test: false
|
||||
};
|
||||
|
||||
const fastify = Fastify({
|
||||
logger: { level: NODE_ENV === 'development' ? 'debug' : 'fatal' }
|
||||
logger: envToLogger[NODE_ENV]
|
||||
}).withTypeProvider<TypeBoxTypeProvider>();
|
||||
|
||||
export type FastifyInstanceWithTypeProvider = typeof fastify;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"@types/supertest": "2.0.12",
|
||||
"jest": "29.5.0",
|
||||
"prisma": "4.10.1",
|
||||
"pino-pretty": "10.0.0",
|
||||
"supertest": "6.3.3",
|
||||
"ts-jest": "29.0.5"
|
||||
},
|
||||
|
||||
@@ -18,7 +18,14 @@ if (error) {
|
||||
`);
|
||||
}
|
||||
|
||||
function isAllowedEnv(
|
||||
env: string
|
||||
): env is 'development' | 'production' | 'test' {
|
||||
return ['development', 'production', 'test'].includes(env);
|
||||
}
|
||||
|
||||
assert.ok(process.env.NODE_ENV);
|
||||
assert.ok(isAllowedEnv(process.env.NODE_ENV));
|
||||
assert.ok(process.env.AUTH0_DOMAIN);
|
||||
assert.ok(process.env.AUTH0_AUDIENCE);
|
||||
assert.ok(process.env.API_LOCATION);
|
||||
|
||||
Generated
+49
-6
@@ -126,6 +126,7 @@ importers:
|
||||
fastify-plugin: ^4.3.0
|
||||
jest: 29.5.0
|
||||
nodemon: 2.0.21
|
||||
pino-pretty: 10.0.0
|
||||
prisma: 4.10.1
|
||||
supertest: 6.3.3
|
||||
ts-jest: 29.0.5
|
||||
@@ -144,6 +145,7 @@ importers:
|
||||
'@fastify/type-provider-typebox': 2.4.0_naatsb2dmwxq3j32xoqzjtyzqm
|
||||
'@types/supertest': 2.0.12
|
||||
jest: 29.5.0
|
||||
pino-pretty: 10.0.0
|
||||
prisma: 4.10.1
|
||||
supertest: 6.3.3
|
||||
ts-jest: 29.0.5_rvjmdqhqjqm2mi2o3slrod4dxm
|
||||
@@ -10332,7 +10334,7 @@ packages:
|
||||
loader-utils: 2.0.4
|
||||
make-dir: 3.1.0
|
||||
schema-utils: 2.7.1
|
||||
webpack: 5.76.1
|
||||
webpack: 5.76.1_webpack-cli@4.10.0
|
||||
|
||||
/babel-messages/6.23.0:
|
||||
resolution: {integrity: sha512-Bl3ZiA+LjqaMtNYopA9TYE9HP1tQ+E5dLxE0XrAzcIJeK2UqF0/EaqXwBn9esd4UmTfEab+P+UYQ1GnioFIb/w==}
|
||||
@@ -11739,7 +11741,7 @@ packages:
|
||||
resolution: {integrity: sha512-xq+q3SRMOxGivLhBNaUdC64hDTQwejJ+H0T/NB1XMtTVEwNTrfFF3gAxiyW0Bu/xWEGhjVKgUcMhCrUy2+uCWg==}
|
||||
dependencies:
|
||||
base64-js: 1.5.1
|
||||
ieee754: 1.1.13
|
||||
ieee754: 1.2.1
|
||||
isarray: 1.0.0
|
||||
|
||||
/buffer/5.2.1:
|
||||
@@ -13044,7 +13046,7 @@ packages:
|
||||
postcss-value-parser: 4.2.0
|
||||
schema-utils: 3.1.1
|
||||
semver: 7.3.8
|
||||
webpack: 5.76.1
|
||||
webpack: 5.76.1_webpack-cli@4.10.0
|
||||
|
||||
/css-loader/6.7.3_webpack@5.76.1:
|
||||
resolution: {integrity: sha512-qhOH1KlBMnZP8FzRO6YCH9UHXQhVMcEGLyNdb7Hv2cpcmJbW0YrddO+tG1ab5nT41KpHIYGsbeHqxB9xPu1pKQ==}
|
||||
@@ -13420,6 +13422,10 @@ packages:
|
||||
resolution: {integrity: sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA==}
|
||||
engines: {node: '>=0.11'}
|
||||
|
||||
/dateformat/4.6.3:
|
||||
resolution: {integrity: sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==}
|
||||
dev: true
|
||||
|
||||
/dayjs/1.11.7:
|
||||
resolution: {integrity: sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==}
|
||||
|
||||
@@ -15733,6 +15739,10 @@ packages:
|
||||
/fast-copy/2.1.7:
|
||||
resolution: {integrity: sha512-ozrGwyuCTAy7YgFCua8rmqmytECYk/JYAMXcswOcm0qvGoE3tPb7ivBeIHTOK2DiapBhDZgacIhzhQIKU5TCfA==}
|
||||
|
||||
/fast-copy/3.0.1:
|
||||
resolution: {integrity: sha512-Knr7NOtK3HWRYGtHoJrjkaWepqT8thIVGAwt0p0aUs1zqkAzXZV4vo9fFNwyb5fcqK1GKYFYxldQdIDVKhUAfA==}
|
||||
dev: true
|
||||
|
||||
/fast-decode-uri-component/1.0.1:
|
||||
resolution: {integrity: sha512-WKgKWg5eUxvRZGwW8FvfbaH7AXSh2cL+3j5fMGzUMCxWBJ3dV3a7Wz8y2f/uQ0e3B6WmodD3oS54jTQ9HVTIIg==}
|
||||
|
||||
@@ -17938,6 +17948,13 @@ packages:
|
||||
x-xss-protection: 1.3.0
|
||||
dev: false
|
||||
|
||||
/help-me/4.2.0:
|
||||
resolution: {integrity: sha512-TAOnTB8Tz5Dw8penUuzHVrKNKlCIbwwbHnXraNJxPwf8LRtE2HlM84RYuezMFcwOJmoYOCWVDyJ8TQGxn9PgxA==}
|
||||
dependencies:
|
||||
glob: 8.1.0
|
||||
readable-stream: 3.6.1
|
||||
dev: true
|
||||
|
||||
/hexoid/1.0.0:
|
||||
resolution: {integrity: sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -18390,6 +18407,7 @@ packages:
|
||||
|
||||
/ieee754/1.1.13:
|
||||
resolution: {integrity: sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==}
|
||||
dev: false
|
||||
|
||||
/ieee754/1.2.1:
|
||||
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
|
||||
@@ -20466,6 +20484,11 @@ packages:
|
||||
'@sideway/formula': 3.0.1
|
||||
'@sideway/pinpoint': 2.0.0
|
||||
|
||||
/joycon/3.1.1:
|
||||
resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==}
|
||||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
||||
/jquery/3.6.4:
|
||||
resolution: {integrity: sha512-v28EW9DWDFpzcD9O5iyJXg3R3+q+mET5JhnjJzQUZMHOv67bpSIHq81GEYpPNZHG+XXHsfSme3nxp/hndKEcsQ==}
|
||||
dev: false
|
||||
@@ -24115,6 +24138,26 @@ packages:
|
||||
readable-stream: 4.3.0
|
||||
split2: 4.1.0
|
||||
|
||||
/pino-pretty/10.0.0:
|
||||
resolution: {integrity: sha512-zKFjYXBzLaLTEAN1ayKpHXtL5UeRQC7R3lvhKe7fWs7hIVEjKGG/qIXwQt9HmeUp71ogUd/YcW+LmMwRp4KT6Q==}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
colorette: 2.0.19
|
||||
dateformat: 4.6.3
|
||||
fast-copy: 3.0.1
|
||||
fast-safe-stringify: 2.1.1
|
||||
help-me: 4.2.0
|
||||
joycon: 3.1.1
|
||||
minimist: 1.2.8
|
||||
on-exit-leak-free: 2.1.0
|
||||
pino-abstract-transport: 1.0.0
|
||||
pump: 3.0.0
|
||||
readable-stream: 4.3.0
|
||||
secure-json-parse: 2.7.0
|
||||
sonic-boom: 3.2.1
|
||||
strip-json-comments: 3.1.1
|
||||
dev: true
|
||||
|
||||
/pino-std-serializers/6.1.0:
|
||||
resolution: {integrity: sha512-KO0m2f1HkrPe9S0ldjx7za9BJjeHqBku5Ch8JyxETxT8dEFGz1PwgrHaOQupVYitpzbFSYm7nnljxD8dik2c+g==}
|
||||
|
||||
@@ -28727,7 +28770,7 @@ packages:
|
||||
dependencies:
|
||||
loader-utils: 2.0.4
|
||||
schema-utils: 3.1.1
|
||||
webpack: 5.76.1
|
||||
webpack: 5.76.1_webpack-cli@4.10.0
|
||||
|
||||
/style-loader/3.3.1_webpack@5.76.1:
|
||||
resolution: {integrity: sha512-GPcQ+LDJbrcxHORTRes6Jy2sfvK2kS6hpSfI/fXhPt+spVzxF6LJ1dHLN9zIGmVaaP044YKaIatFaufENRiDoQ==}
|
||||
@@ -29135,7 +29178,7 @@ packages:
|
||||
schema-utils: 3.1.1
|
||||
serialize-javascript: 6.0.1
|
||||
terser: 5.16.5
|
||||
webpack: 5.76.1
|
||||
webpack: 5.76.1_webpack-cli@4.10.0
|
||||
|
||||
/terser/4.8.1:
|
||||
resolution: {integrity: sha512-4GnLC0x667eJG0ewJTa6z/yXrbLGv80D9Ru6HIpCQmO+Q4PfEtBFi0ObSckqwL6VyQv/7ENJieXHo2ANmdQwgw==}
|
||||
@@ -30627,7 +30670,7 @@ packages:
|
||||
mime-types: 2.1.35
|
||||
range-parser: 1.2.1
|
||||
schema-utils: 3.1.1
|
||||
webpack: 5.76.1
|
||||
webpack: 5.76.1_webpack-cli@4.10.0
|
||||
|
||||
/webpack-dev-middleware/5.3.3_webpack@5.76.1:
|
||||
resolution: {integrity: sha512-hj5CYrY0bZLB+eTO+x/j67Pkrquiy7kWepMHmUMoPsmcUaeEnQJqFzHJOyxgWlq746/wUuA64p9ta34Kyb01pA==}
|
||||
|
||||
Reference in New Issue
Block a user