-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #913 from superfastcms/fix/logger-http
fix: upgrading pinoHttp
- Loading branch information
Showing
5 changed files
with
49 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Request, RequestHandler } from 'express'; | ||
import pino, { LoggerOptions } from 'pino'; | ||
import { pinoHttp, stdSerializers } from 'pino-http'; | ||
|
||
const httpLoggerOptions: LoggerOptions = { | ||
level: process.env.PUBLIC_LOG_LEVEL || 'info', | ||
redact: { | ||
paths: ['req.headers.authorization', 'req.headers.cookie'], | ||
censor: '--redacted--', | ||
}, | ||
transport: { | ||
target: 'pino-pretty', | ||
options: { | ||
ignore: 'hostname,pid', | ||
hideObject: process.env.PUBLIC_LOG_HIDE_OBJECT || true, | ||
sync: true, | ||
translateTime: 'SYS:HH:MM:ss', | ||
messageFormat: '{req.method} {req.url} {res.statusCode} {responseTime}ms', | ||
}, | ||
}, | ||
}; | ||
|
||
const redactQuery = (originalPath: string) => { | ||
const url = new URL(originalPath, 'http://example.com/'); | ||
|
||
// Access token contained in request parameters. | ||
if (url.searchParams.has('access_token')) { | ||
url.searchParams.set('access_token', '--redacted--'); | ||
} | ||
|
||
return url.pathname + url.search; | ||
}; | ||
|
||
export const expressLogger = pinoHttp({ | ||
logger: pino(httpLoggerOptions), | ||
serializers: { | ||
req(request: Request) { | ||
const output = stdSerializers.req(request); | ||
output.url = redactQuery(output.url); | ||
return output; | ||
}, | ||
}, | ||
}) as RequestHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8651,10 +8651,10 @@ pino-abstract-transport@^1.0.0, [email protected]: | |
readable-stream "^4.0.0" | ||
split2 "^4.0.0" | ||
|
||
pino-http@^8.3.3: | ||
version "8.3.3" | ||
resolved "https://registry.npmjs.org/pino-http/-/pino-http-8.3.3.tgz" | ||
integrity sha512-p4umsNIXXVu95HD2C8wie/vXH7db5iGRpc+yj1/ZQ3sRtTQLXNjoS6Be5+eI+rQbqCRxen/7k/KSN+qiZubGDw== | ||
pino-http@^8.4.0: | ||
version "8.4.0" | ||
resolved "https://registry.yarnpkg.com/pino-http/-/pino-http-8.4.0.tgz#ebfd601f7244d7bd9ead578843025505da4e3f56" | ||
integrity sha512-9I1eRLxsujQJwLQTrHBU0wDlwnry2HzV2TlDwAsmZ9nT3Y2NQBLrz+DYp73L4i11vl/eudnFT8Eg0Kp62tMwEw== | ||
dependencies: | ||
get-caller-file "^2.0.5" | ||
pino "^8.0.0" | ||
|
8b536b8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
superfast – ./
superfast-superfast.vercel.app
superfastcms.vercel.app
superfast-git-main-superfast.vercel.app