-
Notifications
You must be signed in to change notification settings - Fork 210
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
Add configurable logger #434
Conversation
This PR copies the `Log` implementation from Miniflare 2, and allows logging to be configured via the `log` shared option.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like solid OOP code to me 😆
export enum LogLevel { | ||
NONE, | ||
ERROR, | ||
WARN, | ||
INFO, | ||
DEBUG, | ||
VERBOSE, | ||
} | ||
|
||
const LEVEL_PREFIX: { [key in LogLevel]: string } = { | ||
[LogLevel.NONE]: "", | ||
[LogLevel.ERROR]: "err", | ||
[LogLevel.WARN]: "wrn", | ||
[LogLevel.INFO]: "inf", | ||
[LogLevel.DEBUG]: "dbg", | ||
[LogLevel.VERBOSE]: "vrb", | ||
}; | ||
|
||
const LEVEL_COLOUR: { [key in LogLevel]: Colorize } = { | ||
[LogLevel.NONE]: reset, | ||
[LogLevel.ERROR]: red, | ||
[LogLevel.WARN]: yellow, | ||
[LogLevel.INFO]: green, | ||
[LogLevel.DEBUG]: grey, | ||
[LogLevel.VERBOSE]: (input) => dim(grey(input as any)) as any, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non blocking but Enums are rough on the TS server and compiler and turn into functions at runtime.
Could use something like an Object literal or Map for the types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the interest of minimising breaking API changes from Miniflare 2, I think I'll keep this as an enum
, but agree, a const
object literal would be nice here.
This PR copies the
Log
implementation from Miniflare 2, and allows logging to be configured via thelog
shared option. Even though none of our gateways need a logger at the moment, I've added it in case we need it later.