Skip to content

feat(logger): support for NO_COLOR on cloudflare workers #4094

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ryuapp
Copy link
Contributor

@ryuapp ryuapp commented Apr 20, 2025

closes #3751

Note

Currently, process.env is available on Cloudflare Workers with nodejs_compat flag, so there may not be a need to support it.
https://developers.cloudflare.com/workers/runtime-apis/nodejs/process/#processenv

Logger now uses getColorEnabledAsync() to support retrieving cloudflare env. Since we couldn't support this without dynamic import now, I created a new getColorEnabled() that is asynchronous.
getColorEnabled() is maintained for backwards compatibility for showRoute().

The cost of dynamic imports has not been investigated, so it may be necessary to optimize it with following PR:

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

Copy link

codecov bot commented Apr 20, 2025

Codecov Report

Attention: Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.33%. Comparing base (b008006) to head (4a2e1c1).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/utils/color.ts 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4094      +/-   ##
==========================================
+ Coverage   91.29%   91.33%   +0.04%     
==========================================
  Files         168      168              
  Lines       10766    10704      -62     
  Branches     3040     3052      +12     
==========================================
- Hits         9829     9777      -52     
+ Misses        936      926      -10     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ryuapp
Copy link
Contributor Author

ryuapp commented Apr 20, 2025

I also have another plan, #4095.
JSR validation error is related to denoland/deno#28922.

@yusukebe
Copy link
Member

Hi @ryuapp

Thank you for the PR. I think this code is doing a little bit tricky things: dynamic import and calling env. So it's better to write runtime tests. I've created the PR to update wrangler: #4096. Can you review it first?

@ryuapp ryuapp marked this pull request as draft April 21, 2025 15:55
@yusukebe
Copy link
Member

@ryuapp

If it's ready to review, please ping me:)

@ryuapp ryuapp force-pushed the support-for-no_color-on-cloudflare-workers branch from 9d25f4c to d036a85 Compare April 26, 2025 07:43
@ryuapp ryuapp marked this pull request as ready for review April 26, 2025 08:09
Old Cloudflare workers are missing import('cloudflare:workers')
@ryuapp
Copy link
Contributor Author

ryuapp commented Apr 26, 2025

@yusukebe This is now ready for review.

@ryuapp ryuapp force-pushed the support-for-no_color-on-cloudflare-workers branch from ab269b1 to 4a2e1c1 Compare April 27, 2025 12:48
Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

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

LGTM!

@yusukebe
Copy link
Member

Thanks @ryuapp !

I'll merge this later and include the next minor release (maybe shipped soon).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hono Logger ("hono/logger") Disable Coloring
2 participants