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

new: Add colored log levels #1171

Merged
merged 2 commits into from
May 4, 2024
Merged

Conversation

camnwalter
Copy link
Contributor

@camnwalter camnwalter commented May 4, 2024

Closes #905
Also see hermit-os/loader#336

Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the PR! :)

This is great, but I have a few visual and technical requests:

Visual requests:

  1. I think we should only color the level (e.g., WARN in [WARN]) and not the whole line.
  2. For color choice I would prefer if we would follow what tracing-subscriber is doing: tracing-subscriber/src/fmt/format/mod.rs#L1504-L1510
  3. We should respect the NO_COLOR environment variable at build time to disable any colors.

Technical requests:

I think it would be good, if we introduced a newtype ColorLevel(Level) that implements a colored 'Display' via anstyle.

@camnwalter
Copy link
Contributor Author

I think it would be good, if we introduced a newtype ColorLevel(Level) that implements a colored 'Display' via anstyle.

anstyle comes with the stdlib, so do you want me to re-create what they do?

Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anstyle comes with the stdlib, so do you want me to re-create what they do?

If you disable the default std feature, it should work:

anstyle = { version = "1", default-features = false }

Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is looking great. Could you remove the explicit types from the let bindings unless necessary? :)

Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! :)

@mkroening mkroening added this pull request to the merge queue May 4, 2024
Merged via the queue into hermit-os:main with commit 87ebdd3 May 4, 2024
13 checks passed
@camnwalter
Copy link
Contributor Author

camnwalter commented May 4, 2024

No problem! I'll do similar changes in the other pull request in a little bit

@camnwalter camnwalter deleted the color-logging branch May 5, 2024 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add colors to log levels
2 participants