This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(serve): make the registering x from y messages verbose
re #50
- Loading branch information
Showing
6 changed files
with
111 additions
and
81 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
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 |
---|---|---|
@@ -1,36 +1,39 @@ | ||
import { createLogger, format, transports } from 'winston' | ||
import { createLogger, format, transports, Logger as WinstonLogger } from 'winston' | ||
import { inspect } from 'util' | ||
import escapeStringRegexp from 'escape-string-regexp' | ||
|
||
const serverLogger = createLogger({ | ||
exitOnError: false, | ||
transports: [ | ||
new transports.Console({ | ||
handleExceptions: true, | ||
level: 'debug', | ||
format: format.combine( | ||
format.colorize(), | ||
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), | ||
format.errors({ stack: true }), | ||
format.printf((info) => { | ||
let result = `${info.timestamp} - ${info.level}: ` | ||
export type Logger = WinstonLogger | ||
|
||
let message = | ||
typeof info.message === 'object' ? inspect(info.message, false, 4, true) : info.message | ||
export const createServerLogger = (logLevel: string): Logger => | ||
createLogger({ | ||
exitOnError: false, | ||
transports: [ | ||
new transports.Console({ | ||
handleExceptions: true, | ||
level: logLevel, | ||
format: format.combine( | ||
format.colorize(), | ||
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), | ||
format.errors({ stack: true }), | ||
format.printf((info) => { | ||
let result = `${info.timestamp} - ${info.level}: ` | ||
|
||
const matchedError = info.stack?.match(/Error: (.*)/) | ||
if (matchedError && matchedError[1]) { | ||
const escapedMatch = escapeStringRegexp(matchedError[1]) | ||
message = message.replace(new RegExp(`${escapedMatch}$`), '') | ||
} | ||
let message = | ||
typeof info.message === 'object' ? inspect(info.message, false, 4, true) : info.message | ||
|
||
result += message | ||
result += info.stack ? `\n${info.stack}` : '' | ||
return result | ||
}), | ||
), | ||
}), | ||
], | ||
}) | ||
const matchedError = info.stack?.match(/Error: (.*)/) | ||
if (matchedError && matchedError[1]) { | ||
const escapedMatch = escapeStringRegexp(matchedError[1]) | ||
message = message.replace(new RegExp(`${escapedMatch}$`), '') | ||
} | ||
|
||
export default serverLogger | ||
result += message | ||
result += info.stack ? `\n${info.stack}` : '' | ||
return result | ||
}), | ||
), | ||
}), | ||
], | ||
}) | ||
|
||
export default createServerLogger |
Oops, something went wrong.