1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-11-10 21:22:20 +03:00
Files
mvfst/quic/logging/QuicLogger.h
Subodh Iyengar 5ae32c3789 only execute logger when it is on
Summary: this gates calling quic logging only until the logger is on. The static trace probes cause the toStrings to be invoked even though the probes are not active. This is not great. We haven't used the probes in a very long time, so let's just disable them

Reviewed By: mjoras

Differential Revision: D18758993

fbshipit-source-id: 4ccce3374cbf431607fc8d5fb5a29410c7f94529
2019-12-02 17:49:05 -08:00

75 lines
1.9 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
#pragma once
#include <folly/tracing/StaticTracepoint.h>
#include <quic/codec/QuicConnectionId.h>
#include <quic/state/StateData.h>
namespace quic {
class Logger {
public:
virtual ~Logger() = default;
virtual void logTrace(
const std::string& name,
const QuicConnectionStateBase& conn,
std::chrono::steady_clock::time_point time,
const std::string& value) = 0;
};
template <class T>
void quicTraceStream(std::string& value, T&& t) {
value += folly::to<std::string>(t);
}
template <class T, class... Args>
void quicTraceStream(std::string& value, T&& t, Args&&... args) {
value += folly::to<std::string>(t, ", ");
quicTraceStream(value, std::forward<Args>(args)...);
}
template <class T, class... Args>
void quicTraceLogger(std::string name, const T& conn, Args&&... args) {
std::string value;
quicTraceStream(value, std::forward<Args>(args)...);
VLOG(20) << name << " [" << conn << "] " << value;
if (conn.logger) {
conn.logger->logTrace(name, conn, std::chrono::steady_clock::now(), value);
}
}
#if FOLLY_MOBILE
#define QUIC_LOGGER(name, conn, ...) (void)conn;
#else
#define QUIC_LOGGER(name, connmacro, ...) \
if ((connmacro).logger || VLOG_IS_ON(20)) { \
quicTraceLogger(#name, connmacro, __VA_ARGS__); \
}
#endif
#if QUIC_TPERF
#define QUIC_TRACE(name, conn, ...) ;
#else
#define QUIC_TRACE(name, conn, ...) \
do { \
QUIC_LOGGER(name, conn, __VA_ARGS__) \
} while (false);
#endif
#define QUIC_TRACE_SOCK(name, sock, ...) \
if (sock && sock->getState()) { \
QUIC_TRACE(name, *(sock)->getState(), __VA_ARGS__); \
}
} // namespace quic