elastic/kibana

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

オープン

#214,725 opened on 2025/03/17

 (3 件のコメント) (0 件のリアクション) (0 人の担当者)TypeScript (8,021 件のフォーク)batch import
Feature:LoggingTeam:Coregood first issue

Repository metrics

Stars
 (19,065 個のスター)
PR merge metrics
 (平均マージ 1d 16h) (30d で 999 merged PRs)

説明

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.

コントリビューターガイド