Skip to content

Commit

Permalink
Update implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
JR40159 committed Oct 25, 2024
1 parent d2f4c77 commit 35a0944
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/src/routes/middleware/expressLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const morganLog = promisify(
requestId: req.reqId,
...(tokens.res(req, res, 'content-length') && { 'content-length': tokens.res(req, res, 'content-length') }),
}
req.log.debug(info)
req.log.debug(info, 'Request completed')

return ''
},
Expand Down
10 changes: 5 additions & 5 deletions backend/src/services/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface BunyanLog {
msg: string
}

interface RequestLog extends BunyanLog {
interface RequestCompletedLog extends BunyanLog {
method: string
url: string
status: number
Expand Down Expand Up @@ -84,9 +84,9 @@ export class Writer extends WritableStream {
return typeof value === 'object' ? util.inspect(value) : String(value)
}

static isRequest(data: any): data is RequestLog {
static isRequestCompleted(data: any): data is RequestCompletedLog {
const keys = Object.keys(data)
return ['requestId', 'url', 'method'].every((k) => keys.includes(k))
return ['requestId', 'url', 'method'].every((k) => keys.includes(k)) && data.msg === 'Request completed'
}

static getAttributes(data: any) {
Expand All @@ -105,7 +105,7 @@ export class Writer extends WritableStream {
])
let keys = Object.keys(attributes)

if (Writer.isRequest(data)) {
if (Writer.isRequestCompleted(data)) {
// this is probably a req object.
attributes = omit(attributes, ['requestId', 'agent'])
keys = Object.keys(attributes)
Expand Down Expand Up @@ -137,7 +137,7 @@ export class Writer extends WritableStream {
const formattedAttributes = attributes.length ? `${data.msg ? ' ' : ''}(${attributes})` : ''

let message
if (Writer.isRequest(data)) {
if (Writer.isRequestCompleted(data)) {
message = `${level} - ${data.status} ${data.method} ${data.url} ${data['response-time']}ms`
} else {
message = `${level} - (${src}): ${data.msg}${formattedAttributes}`
Expand Down

0 comments on commit 35a0944

Please sign in to comment.