Skip to content

Commit

Permalink
[Backend] Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
valtterikantanen committed Oct 9, 2024
1 parent f6d3728 commit c198259
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 9 additions & 3 deletions services/backend/src/util/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ const logger = winston.createLogger({
format: combine(
colorize(),
timestamp({ format: isProduction ? 'D.M.YYYY,HH.mm.ss' : 'HH.mm.ss' }),
printf(({ level, message, timestamp, error }) => {
const log = `${timestamp} ${level}: ${message}`
return error?.stack ? `${log}\n${error.stack}` : log
printf(({ level, message, timestamp, error, meta }) => {
let log = `${timestamp} ${level}: ${message}`
if (error?.stack) {
log = `${log}\n${error.stack}`
}
if (Object.keys(meta || {}).length > 0) {
log = `${log}\n${JSON.stringify(meta, null, 2)}`
}
return log
})
),
transports,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@ export const TeacherLeaderBoard = () => {
}))

const lastUpdated = new Date(topTeachers?.updated).toLocaleString(undefined, {
year: 'numeric',
month: 'long',
day: 'numeric',
minute: 'numeric',
hour: 'numeric',
second: 'numeric',
dateStyle: 'long',
timeStyle: 'medium',
})

return (
Expand Down

0 comments on commit c198259

Please sign in to comment.