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

feat(utils/color): support cloudflare workers (edge) #3752

Closed
wants to merge 12 commits into from

Conversation

EdamAme-x
Copy link
Contributor

@EdamAme-x EdamAme-x commented Dec 16, 2024

Closes: #3751

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

@EdamAme-x EdamAme-x changed the title feat(utils/color): support cloudflare workers feat(utils/color): support cloudflare workers (edge) Dec 16, 2024
@EdamAme-x EdamAme-x marked this pull request as draft December 16, 2024 03:20
Copy link

codecov bot commented Dec 16, 2024

Codecov Report

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

Project coverage is 91.73%. Comparing base (4eb101d) to head (dc73ca2).

Files with missing lines Patch % Lines
src/utils/color.ts 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3752      +/-   ##
==========================================
+ Coverage   91.72%   91.73%   +0.01%     
==========================================
  Files         159      159              
  Lines       10178    10180       +2     
  Branches     2896     2885      -11     
==========================================
+ Hits         9336     9339       +3     
+ Misses        841      840       -1     
  Partials        1        1              

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

@EdamAme-x
Copy link
Contributor Author

After school, I will add tests for deno

@EdamAme-x EdamAme-x marked this pull request as ready for review December 16, 2024 04:50
@EdamAme-x
Copy link
Contributor Author

Hi @kingmesal.
Can you review this?

@yusukebe
Copy link
Member

Hi @EdamAme-x

Thank you for the PR. But I can't agree on this way using NO_COLOR in c.env. It will be confusing if someone uses NO_COLOR in c.env for another purpose. I think the better way is to create colorized option for the Logger middleware and write it like this:

const app = new Hono<{
  Bindings: {
    NO_COLOR: boolean
  }
}>()

app.use(async (c, next) => {
  return logger(undefined, {
    colorized: !c.env.NO_COLOR,
  })
})

But, I'm not sure it is best to add options for the second arg of logger.

@yusukebe
Copy link
Member

We use NO_COLOR variable in process.env since it's de facto standard on the Node.js environment:

https://no-color.org/

But, I think we don't have the manner in Cloudflare Workers.

@EdamAme-x
Copy link
Contributor Author

I agree there is an option to add an opt
ion. (Colored, noColor, etc)

@EdamAme-x
Copy link
Contributor Author

@kingmesel
What do you think?

@kingmesal
Copy link

My perspective is that the simpler and more consistent, the solution the better.

I think if it were on the c.env it is the simplest, but I can understand the argument that it is possible (albeit highly unlikely) that someone has used an c.env.NO_COLOR somewhere.

Passing in options is useful as it makes it pretty easy for people to find and alter the logger functionality, which I think is probably the better reason to use that approach over the c.env directly.

@StuartMoncrieff
Copy link

I have created a PR to update the website with a tip on using the NO_COLOR environment variable to disable ANSI escape codes in the output from the build-in logger middleware (honojs/website#553).

@kingmesal has noted that the default logging behaviour on CloudFlare Workers is to not have colored log output, which makes this PR unnecessary (sorry @EdamAme-x!).

Note that the default behavior of the logger on CloudFlare Workers is different to Node/Bun/Deno, which default to colored status codes.

@EdamAme-x
Copy link
Contributor Author

okay, I will close this

@EdamAme-x EdamAme-x closed this Dec 20, 2024
@yusukebe
Copy link
Member

@StuartMoncrieff @EdamAme-x Thanks!

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.

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