elastic/kibana

[logger] `log.debug` and `.trace` should prefer the lazy implementation

Offen

#214.725 geöffnet am 17.03.2025

 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (8.021 Forks)batch import
Feature:LoggingTeam:Coregood first issue

Repository-Metriken

Stars
 (19.065 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 1T 16h) (999 gemergte PRs in 30 T)

Beschreibung

There are many places where we do patterns like log.debug(`${JSON.stringify({...})}`) in the Kibana code.

When the log level is set higher than debug, this implies unnecessary CPU blocks only to be discarded later.

We should audit all use cases like this and change them to the lazy form: ``````log.debug(() => ${JSON.stringify({...})})```.

@dgieselaar provided the following RegExp to find all use cases:

\.(?:debug|trace)\(\s*(?!((?:\([^)]*\)|\w+)\s*=>)).*?JSON\.stringify\s*\(

Please, bear in mind that some loggers don't support this. Make sure to only update the ones using the Logger from @kbn/logger.

Ideally, an autofixable ESlint rule would prevent this from happening again.

Contributor Guide