1
#include "source/common/http/http2/nghttp2.h"
2

            
3
#include "source/common/common/logger.h"
4

            
5
// nghttp2 fails to convey the POSIX ssize_t declaration
6
// that Microsoft declines to implement. Pick up a valid
7
// ssize_t declaration for win32 in our platform.h
8
#include "envoy/common/platform.h"
9

            
10
#include "nghttp2/nghttp2.h"
11

            
12
namespace Envoy {
13
namespace Http {
14
namespace Http2 {
15

            
16
1665
void initializeNghttp2Logging() {
17
  // When ENVOY_NGHTTP2_TRACE is set, we install a debug logger, to prevent nghttp2
18
  // logging directly to stdout at -l trace.
19
1665
  nghttp2_set_debug_vprintf_callback([](const char* format, va_list args) {
20
    if (std::getenv("ENVOY_NGHTTP2_TRACE") != nullptr) {
21
      char buf[2048];
22
      const int n = ::vsnprintf(buf, sizeof(buf), format, args);
23
      // nghttp2 inserts new lines, but we also insert a new line in the ENVOY_LOG
24
      // below, so avoid double \n.
25
      if (n >= 1 && static_cast<size_t>(n) < sizeof(buf) && buf[n - 1] == '\n') {
26
        buf[n - 1] = '\0';
27
      }
28
      ENVOY_LOG_TO_LOGGER(Logger::Registry::getLog(Logger::Id::http2), trace, "nghttp2: {}", buf);
29
    }
30
  });
31
1665
}
32

            
33
} // namespace Http2
34
} // namespace Http
35
} // namespace Envoy