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

[Suggestion / Frameworks] Log level and log customization #1220

Closed
arpowers opened this issue Dec 9, 2020 · 5 comments
Closed

[Suggestion / Frameworks] Log level and log customization #1220

arpowers opened this issue Dec 9, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@arpowers
Copy link
Contributor

arpowers commented Dec 9, 2020

Just a simple request to make logging customizable for frameworks.

Specifically, we'd like to integrate the vite logging into the logging style used by the upcoming Factor headless-framework.

Additionally, the log level should be supported.

Currently, you're just logging stuff like this:

console.log(`[vite] connected.`)

For your consideration, you could use the format:

vlog("warn", "context", data)
vlog("success", "success context", data)
vlog("info", "info context", data)
// etc...

Within the vlog function you could allow customization, as well as apply level handling and formatting...

@arpowers arpowers changed the title [Suggestion / Frameworks] Log level and customization [Suggestion / Frameworks] Log level and log customization Dec 9, 2020
@aleclarson
Copy link
Member

I've written up a logger in #1015 that we can build upon (see the code here). It doesn't yet have log levels or the [vite] prefix. Currently, it can be silenced and it can stack spinners (where the most recent spinner takes precedence).
As I mentioned here, I'd prefer to avoid a global logger, which makes it harder to silence logs for duplicate requests within a short timeframe.

@aleclarson aleclarson added the enhancement New feature or request label Dec 9, 2020
@arpowers
Copy link
Contributor Author

arpowers commented Dec 9, 2020

we'd recommend the global logging utility, without a doubt. In the rare scenarios when a ton of rapid logging is happening just deal with that "in context" using lodash throttle or similar...

Some tips on formatting:

In node, we add some nice formatting using CLI Highlight, PrettyOutput, and Consola for errors.

In the browser we add some formatting like this:

console.log(
      `%c${category} > ${description}`,
      `font-weight:bold;color: ${color};padding: 5px 0;${additional}`,
      data ?? "",
    )
  }

@aleclarson
Copy link
Member

aleclarson commented Dec 9, 2020

What exactly is the benefit of a global logger?

deal with that "in context" using lodash throttle or similar...

That wouldn't work. Logging spans across modules and even plugins. The point of request-specific loggers is being able to "mute" an entire request, not to throttle its logs arbitrarily.

@arpowers
Copy link
Contributor Author

arpowers commented Dec 9, 2020

Create a singleton then and throttle that.

The benefit is DRY code that can be modified or extended in one place.

@yyx990803
Copy link
Member

Addressed in 2.0 via https://vitejs.dev/config/#loglevel

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants