Construct HTTP log message only if needed (#165057)

## Summary

Previously we have unconditionally created a debug log message that
potentially involved serializing a large response object only to ignore
it if the the log level 'debug' is disabled for that logger. With this
commit we add a check if the respective level is enabled on the logger
before we proceed to construct the log message.

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
This commit is contained in:
Daniel Mitterdorfer 2023-08-29 10:15:18 +02:00 committed by GitHub
parent 34c7a03016
commit aa27425663
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -399,8 +399,10 @@ export class HttpServer {
const log = this.logger.get('http', 'server', 'response');
this.handleServerResponseEvent = (request) => {
const { message, meta } = getEcsResponseLog(request, this.log);
log.debug(message!, meta);
if (log.isLevelEnabled('debug')) {
const { message, meta } = getEcsResponseLog(request, this.log);
log.debug(message!, meta);
}
};
this.server.events.on('response', this.handleServerResponseEvent);