Skip to content

feat(logger): improve automatic color support detection#3017

Draft
NamesMT wants to merge 2 commits intohonojs:mainfrom
NamesMT:fix/better-color-support-detect
Draft

feat(logger): improve automatic color support detection#3017
NamesMT wants to merge 2 commits intohonojs:mainfrom
NamesMT:fix/better-color-support-detect

Conversation

@NamesMT
Copy link
Copy Markdown
Contributor

@NamesMT NamesMT commented Jun 21, 2024

The current color detection is not great and the log message in CloudWatch logs is hard to read.
image

The PR adds utils/flags.ts and improve getColorEnabled() using isColorSupported flag The flag have been moved to inline of the function to align with the current test cases.

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

Comment thread src/utils/color.ts
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { process, Deno } = globalThis as any

// It is put as a function instead of a constant to only to run as needed in the ternary operator.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Revising in 2025:

isColorSupported was put here instead of flags because Cloudflare Workers in the past does include the env variables on the global process.env and we couldn't check for NO_COLOR, FORCE_COLOR.

If we're reviving this PR, we move it to flags now as Workers have supported it.

Comment thread src/utils/color.ts
const { process, Deno } = globalThis as any

// It is put as a function instead of a constant to only to run as needed in the ternary operator.
const isColorSupported = () =>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry if I'm misunderstanding. On Cloudflare Workers, this value returns from isColorSupported() is always false, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think so, unless the user sets FORCE_COLOR, anyways, let me do a refresh update and do actual test with Lambda + Workers to see if it works normally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What do you think of the added flags.ts, is it good to you?, or should I inline everything in the getColorEnabled?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think adding flags.ts is good. Let's go with it.

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.

2 participants