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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

made nestLike output closer to nestjs #773

Merged
merged 1 commit into from
Nov 22, 2023
Merged
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
made nestLike output closer to nestjs
  • Loading branch information
tobias committed Nov 22, 2023
commit 1f8744f0d8d8eee20974142686718e7771006add
10 changes: 7 additions & 3 deletions src/winston.utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const clc = {
};

const nestLikeColorScheme: Record<string, (text: string) => string> = {
info: clc.green,
log: clc.green,
error: clc.red,
warn: clc.yellow,
debug: clc.magentaBright,
Expand All @@ -29,6 +29,10 @@ const nestLikeConsoleFormat = (
},
): Format =>
format.printf(({ context, level, timestamp, message, ms, ...meta }) => {
if ('info' === level) {
level = 'log';
}

if ('undefined' !== typeof timestamp) {
// Only format the timestamp to a locale representation if it's ISO 8601 format. Any format
// that is not a valid date string will throw, just ignore it (it will be printed as-is).
Expand All @@ -51,9 +55,9 @@ const nestLikeConsoleFormat = (
: stringifiedMeta;

return (
`${color(`[${appName}]`)} ` +
`${yellow(level.charAt(0).toUpperCase() + level.slice(1))}\t` +
color(`[${appName}] ${String(process.pid).padEnd(6)} - `) +
('undefined' !== typeof timestamp ? `${timestamp} ` : '') +
`${color(level.toUpperCase().padStart(7))}\t` +
('undefined' !== typeof context
? `${yellow('[' + context + ']')} `
: '') +
Expand Down