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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable logger #434

Merged
merged 1 commit into from
Nov 17, 2022
Merged

Add configurable logger #434

merged 1 commit into from
Nov 17, 2022

Conversation

mrbbot
Copy link
Contributor

@mrbbot mrbbot commented Nov 17, 2022

This PR copies the Log implementation from Miniflare 2, and allows logging to be configured via the log shared option. Even though none of our gateways need a logger at the moment, I've added it in case we need it later.

This PR copies the `Log` implementation from Miniflare 2, and allows
logging to be configured via the `log` shared option.
@mrbbot mrbbot added the tre Relating to Miniflare 3 label Nov 17, 2022
@mrbbot mrbbot added this to the 3.0.0 milestone Nov 17, 2022
@changeset-bot
Copy link

changeset-bot bot commented Nov 17, 2022

⚠️ No Changeset found

Latest commit: 213eafb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

@JacobMGEvans JacobMGEvans left a 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 😆

Comment on lines +7 to +32
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,
};

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?

Copy link
Contributor Author

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.

@mrbbot mrbbot merged commit fe7111e into tre Nov 17, 2022
@mrbbot mrbbot deleted the tre-configurable-logger branch November 17, 2022 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tre Relating to Miniflare 3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants