log#
-
namespace heph
Functions
-
template<typename ...Args>
void log(LogLevel level, telemetry::MessageWithLocation &&msg, Args&&... fields) noexcept# Log a message. Example:
heph::log(heph::LogLevel::WARN, "speed is over limit", "current_speed", 31.3, "limit", 30.0, "entity", "km/h")
-
template<typename ...Args>
void log(LogLevel level, telemetry::MessageWithLocation &&msg) noexcept# Log a message without fields. Example:
heph::log(heph::LogLevel::WARN, "speed is over limit")
-
template<typename ...Args>
void logIf(LogLevel level, bool condition, telemetry::MessageWithLocation &&msg, Args&&... fields) noexcept# Conditionally log a message. Example:
heph::log(heph::LogLevel::WARN, a==3, "speed is over limit", "current_speed", 31.3, "limit", 30.0, "entity", "km/h")
-
template<typename ...Args>
void logIf(LogLevel level, bool condition, telemetry::MessageWithLocation &&msg) noexcept# Conditionally log a message without fields. Example:
heph::log(heph::LogLevel::WARN, a==3, "speed is over limit")
-
namespace telemetry#
Functions
-
telemetry::ILogSink ®isterLogSink(std::unique_ptr<telemetry::ILogSink> sink) noexcept#
Register a sink for logging.
-
template<typename TSink, typename ...Args>
TSink &makeAndRegisterLogSink(Args&&... args) noexcept# Create and register a sink for logging.
-
bool removeLogSink(telemetry::ILogSink &sink) noexcept#
Remove a registered log sink. Returns
trueon removal success,falseotherwise.
-
void removeAllLogSinks() noexcept#
Remove all registered log sinks.
-
void flushLogEntries()#
Flush all log entries to the sink. Block until flush is completed.
NOTE: if messages keep coming, this could block forever.
-
telemetry::ILogSink ®isterLogSink(std::unique_ptr<telemetry::ILogSink> sink) noexcept#
-
template<typename ...Args>
-
namespace heph
Enums
-
namespace telemetry
-
template<typename T>
struct Field#
-
struct ILogSink#
- #include “/home/runner/.bazel/sandbox/processwrapper-sandbox/341/execroot/_main/modules/telemetry/log/include/hephaestus/telemetry/log/log_sink.h”
Interface for sinks that log entries can be sent to.
-
struct LogEntry#
- #include “/home/runner/.bazel/sandbox/processwrapper-sandbox/341/execroot/_main/modules/telemetry/log/include/hephaestus/telemetry/log/log_sink.h”
A class that allows easy composition of logs for structured logging. Example(see also log.cpp):
cpp namespace ht=heph::telemetry; log(LogLevel::INFO, "adding", "speed", 31.3, "tag", "test");logs ‘level=info hostname=goofy location=log.h:123 thread-id=5124 time=2023-12-3T8:52:02+0 module=”my module” message=”adding” id=12345 speed=31.3 tag=”test”’ Remark: We would like to use libfmt with quoted formatting as proposed in fmtlib/fmt#825 once its included (instead of sstream).Public Types
Public Members
Public Functions
-
LogEntry(LogLevel level, MessageWithLocation &&message)#
-
template<NonQuotable T>
inline LogEntry &&operator<<(const Field<T> &field)# General loginfo consumer, should be used like LogEntry(“my message”) << Field{“field”, 1234} Converted to string with stringstream.
- Template Parameters:
T – any type that is consumeable by stringstream
- Parameters:
key – identifier for the logging data
value – value of the logging data
- Returns:
LogEntry&&
-
template<Quotable S>
inline LogEntry &&operator<<(const Field<S> &field)# Specialized loginfo consumer for string types so that they are quoted, should be used like LogEntry(“my message”) << Field{“field”, “mystring”}.
- Template Parameters:
T – any type that is consumeable by stringstream
- Parameters:
key – identifier for the logging data
val – value of the logging data
- Returns:
LogEntry&&
-
LogEntry(LogLevel level, MessageWithLocation &&message)#
-
struct MessageWithLocation#
- #include “/home/runner/.bazel/sandbox/processwrapper-sandbox/341/execroot/_main/modules/telemetry/log/include/hephaestus/telemetry/log/log_sink.h”
Wrapper around string literals to enhance them with a location. Note that the message is not owned by this class. We need to use a const char* here in order to enable implicit conversion from
log(LogLevel::INFO,"my string");. The standard guarantees that string literals exist for the entirety of the program lifetime, so it is fine to use it asMessageWithLocation("my message");
-
template<typename T>
-
namespace telemetry
-
template<>
struct formatter<heph::telemetry::Field<std::string>> : public fmt::formatter<std::string_view>#
-
template<>
struct formatter<heph::telemetry::LogEntry> : public fmt::formatter<std::string_view># - #include “/home/runner/.bazel/sandbox/processwrapper-sandbox/341/execroot/_main/modules/telemetry/log/include/hephaestus/telemetry/log/log_sink.h”
Formatter for LogEntry adhering to logfmt rules.
-
namespace heph
-
namespace telemetry
-
class AbslLogSink : public heph::telemetry::ILogSink#
- #include “/home/runner/.bazel/sandbox/processwrapper-sandbox/341/execroot/_main/modules/telemetry/log/include/hephaestus/telemetry/log/sinks/absl_sink.h”
A simple sink that passes the logs to ABSL. Per default entry is formatted via heph::telemetry::format.
-
class AbslLogSink : public heph::telemetry::ILogSink#
-
namespace telemetry