mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[Kibana logging system] Add conditional evaluation based on level for logging APIs (#187225)
## Summary *(Yeah, the title is pretty bad I apologize, I couldn't find something sexy. OTOH, "sexy" and "logging" are usually antonyms, like "sport car" and "fiat panda", or "server language" and "javascript")* ### 1. Provide a more developer-friendly alternative to `Logger.isLevelEnabled`. **With `isLevelEnabled`** ```ts if(logger.isLevelEnabled('info')) { const message = someExpensiveMessageProbablyBasedOnJsonStringifyOrSomething(); logger.info(message); } ``` **With this PR:** ```ts logger.info(() => someExpensiveMessageProbablyBasedOnJsonStringifyOrSomething()); ``` ### 2. Adapt calls to `log.debug` (arguably) costly to use this syntax Aka any call relying on `JSON.stringify` or function calls. I used the new syntax for those, except when the tests were too complicated to fix or when the code did not allow it (e.g. untyped let variables infered from return from assignations don't play well with closures)
This commit is contained in:
parent
a711efa1b2
commit
b6fcfac9c1
116 changed files with 812 additions and 483 deletions
|
@ -10,8 +10,12 @@ import { Logger } from '@kbn/logging';
|
|||
import { Log } from './log';
|
||||
|
||||
export const convertToLogger = (cliLog: Log): Logger => {
|
||||
const getErrorMessage = (msgOrError: string | Error): string => {
|
||||
return typeof msgOrError === 'string' ? msgOrError : msgOrError.message;
|
||||
const getErrorMessage = (msgOrError: string | (() => string) | Error): string => {
|
||||
return typeof msgOrError === 'function'
|
||||
? msgOrError()
|
||||
: typeof msgOrError === 'string'
|
||||
? msgOrError
|
||||
: msgOrError.message;
|
||||
};
|
||||
|
||||
const adapter: Logger = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue