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: runtime logger formatting and debug verbose option #3067

Merged
merged 5 commits into from
Aug 21, 2024

Conversation

BobbieGoede
Copy link
Collaborator

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This changes the runtime debug logging to use a simple logger which prefixes each log with a label: [i18n:${label}], and changes the logging slightly to make it less verbose.

I have also changed the debug option to accept a string 'verbose', now when enabling debug logging the loaded messages objects will not be logged by default but instead only fully log for verbose logging.

The main purpose of this change is to make the debug logs a bit more consistent and allow for easier filtering (especially in the browser) but we could also explore adding basic filtering by label/namespace ourselves.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have added tests (if possible).
  • I have updated the documentation accordingly.

@BobbieGoede BobbieGoede requested a review from kazupon August 19, 2024 14:23
@BobbieGoede BobbieGoede self-assigned this Aug 19, 2024
@kazupon
Copy link
Collaborator

kazupon commented Aug 20, 2024

Thank you!

we should switch from debug to consola.
https://github.com/unjs/consola

there are log level outputing in cosola. :)

@BobbieGoede
Copy link
Collaborator Author

@kazupon
You're right! I've replaced it with consola now but I'm not sure if this is the correct way to use it, for some reason consola won't get treeshaken out even if a project has debug: false πŸ€”

@kazupon
Copy link
Collaborator

kazupon commented Aug 20, 2024

@BobbieGoede
I think @danielroe or @pi0 know more about it. (sorry for metion πŸ™‡ )

src/runtime/messages.ts Outdated Show resolved Hide resolved
src/runtime/utils.ts Outdated Show resolved Hide resolved
@BobbieGoede
Copy link
Collaborator Author

Using the plugins used in https://github.com/vuetifyjs/nuxt-module as a reference, I think I have found a solution by using a virtual file that only imports consola if necessary, it comes with the added benefit of being able to import the logic in both the Nuxt and Nitro context.

I barely understand how this works so I honestly don't know if there are any drawbacks or if this could have been made with a simpler approach.

@@ -49,20 +50,21 @@ export function parseAcceptLanguage(input: string): string[] {

export function getBrowserLocale(): string | undefined {
let ret: string | undefined
const logger = /*#__PURE__*/ createLogger('getBrowserLocale')
Copy link
Collaborator

Choose a reason for hiding this comment

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

We tag the logs with createLogger for each function, do we need to go that far? πŸ˜…

I think it would be better to have a logger tagged per js/ts module.
I believe we can make debugging more efficient from currently by filtering the logs by module.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree it seems like a bit much, but most of the logs originally already had the function name in the log itself in each log statement (for example https://github.com/nuxt-modules/i18n/pull/3067/files/a44ce5dbcd40696e2cfd3db47b18464476a5cb45#diff-7755b40274cbd4ca5d224c6ed6953280e589110e9289595aeb246ff4a1c07448L57).

The primary reason for tagging them is so the actual code/logic is easier to read and understand (fewer multiline debug log statements, less word repetition). With these refactors I'm hoping to find patterns for simplification like in #3063.

Logging per module/file would definitely make more sense, and I think the fact that we had the function name in the logs probably means that internal.ts and utils.ts` are not descriptive enough, which we could solve by splitting these up further.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The primary reason for tagging them is so the actual code/logic is easier to read and understand (fewer multiline debug log statements, less word repetition). With these refactors I'm hoping to find patterns for simplification like in #3063.

Okay, I could understand what you are trying to improve for logging. Let's continue to refactor and improve! :)

@kazupon kazupon merged commit 80d9e60 into nuxt-modules:main Aug 21, 2024
7 checks passed
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.

3 participants