Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rest-api(fix): Denest keys for logs #3230

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/rest-api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const port = process.env.PORT || 3000
app.use(express.json())

app.use((req, res, next) => {
logger.info('Incoming request', {
logger.info({
msg: 'Incoming request',
method: req.method,
path: req.path,
query: req.query,
Expand All @@ -22,7 +23,8 @@ app.use((req, res, next) => {

const originalJson = res.json
res.json = function (body) {
logger.info('Outgoing response', {
logger.info({
msg: 'Outgoing response',
method: req.method,
path: originalPath,
statusCode: res.statusCode,
Expand Down
8 changes: 8 additions & 0 deletions packages/rest-api/src/middleware/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format((info) => {
if (typeof info.message === 'object') {
Object.assign(info, info.message)
}
info.msg = info.msg || info.message
delete info.message
return info
})(),
winston.format.json()
),
transports,
Expand Down
Loading