9 #include "quill/core/Attributes.h" 10 #include "quill/core/Codec.h" 11 #include "quill/core/LogLevel.h" 12 #include "quill/core/MacroMetadata.h" 14 #include "quill/bundled/fmt/format.h" 20 #include <string_view> 35 using FormatBuffer = fmtquill::basic_memory_buffer<char, 88>;
51 : timestamp(other.timestamp),
52 macro_metadata(other.macro_metadata),
53 logger_base(other.logger_base),
54 formatted_msg(std::move(other.formatted_msg)),
64 macro_metadata = &
extra_data->runtime_metadata.macro_metadata;
73 timestamp = other.timestamp;
74 macro_metadata = other.macro_metadata;
75 logger_base = other.logger_base;
76 formatted_msg = std::move(other.formatted_msg);
84 macro_metadata = &
extra_data->runtime_metadata.macro_metadata;
94 other.timestamp = timestamp;
95 other.macro_metadata = macro_metadata;
96 other.logger_base = logger_base;
100 other.formatted_msg->clear();
101 other.formatted_msg->reserve(formatted_msg->size());
102 other.formatted_msg->append(*formatted_msg);
106 other.
extra_data = std::make_unique<ExtraData>(*extra_data);
108 if (other.
extra_data->runtime_metadata.has_runtime_metadata)
111 other.macro_metadata = &other.
extra_data->runtime_metadata.macro_metadata;
117 QUILL_NODISCARD QUILL_ATTRIBUTE_HOT LogLevel log_level()
const noexcept
119 return macro_metadata->log_level();
123 QUILL_NODISCARD QUILL_ATTRIBUTE_HOT std::vector<std::pair<std::string, std::string>>* get_named_args()
const noexcept
127 if (!
extra_data || !macro_metadata || !macro_metadata->has_named_args())
136 QUILL_NODISCARD QUILL_ATTRIBUTE_HOT std::string_view mdc()
const noexcept
142 QUILL_ATTRIBUTE_HOT
void ensure_extra_data()
152 QUILL_ATTRIBUTE_HOT
void set_flush_flag(std::atomic<bool>* flush_flag_ptr) noexcept
157 QUILL_NODISCARD QUILL_ATTRIBUTE_HOT std::atomic<bool>* flush_flag()
const noexcept
159 QUILL_ASSERT(std::holds_alternative<std::atomic<bool>*>(
event_payload),
160 "Attempted to read a flush flag from a TransitEvent with a non-flush payload");
161 std::atomic<bool>*
const flush_flag_ptr = std::get<std::atomic<bool>*>(
event_payload);
162 QUILL_ASSERT(flush_flag_ptr !=
nullptr,
163 "Attempted to read a null flush flag from a TransitEvent");
164 return flush_flag_ptr;
167 QUILL_ATTRIBUTE_HOT
void set_metric_value(
double value) noexcept {
event_payload = value; }
169 QUILL_ATTRIBUTE_HOT
void reset_payload() noexcept {
event_payload = std::monostate{}; }
171 QUILL_NODISCARD QUILL_ATTRIBUTE_HOT
bool has_metric_value()
const noexcept
176 QUILL_NODISCARD QUILL_ATTRIBUTE_HOT
double metric_value()
const noexcept
178 QUILL_ASSERT(has_metric_value(),
179 "Attempted to read a metric value from a TransitEvent without one");
187 RuntimeMetadata(
char const* file, uint32_t line,
char const*
function,
char const* in_tags,
188 char const* in_fmt, LogLevel log_level)
189 : fmt(_safe_string(in_fmt)),
190 source_location(_format_file_location(file, line)),
191 function_name(_safe_string(
function)),
192 tags(_safe_string(in_tags)),
193 macro_metadata(source_location.data(), function_name.data(), fmt.data(),
194 tags.empty() ? nullptr : tags.data(), log_level, MacroMetadata::Event::Log),
195 has_runtime_metadata(
true)
201 source_location(other.source_location),
202 function_name(other.function_name),
204 macro_metadata(source_location.data(), function_name.data(), fmt.data(),
205 tags.empty() ? nullptr : tags.data(), other.macro_metadata.log_level(),
206 MacroMetadata::Event::Log),
207 has_runtime_metadata(other.has_runtime_metadata)
217 source_location = other.source_location;
218 function_name = other.function_name;
220 has_runtime_metadata = other.has_runtime_metadata;
223 macro_metadata =
MacroMetadata(source_location.data(), function_name.data(), fmt.data(),
224 tags.empty() ? nullptr : tags.data(),
225 other.macro_metadata.log_level(), MacroMetadata::Event::Log);
234 std::string source_location;
235 std::string function_name;
238 bool has_runtime_metadata{
false};
241 QUILL_NODISCARD
static char const* _safe_string(
char const* value) noexcept
243 return value ? value :
"";
246 QUILL_NODISCARD
static std::string _format_file_location(
char const* file, uint32_t line)
248 if (!file || (file[0] ==
'\0' && line == 0))
250 return std::string{};
254 return std::string{file} +
":" + std::to_string(line);
262 std::vector<std::pair<std::string, std::string>> named_args;
267 uint64_t timestamp{0};
270 std::unique_ptr<FormatBuffer> formatted_msg{std::make_unique<FormatBuffer>()};
std::unique_ptr< ExtraData > extra_data
buffer for message
Definition: TransitEvent.h:271
Definition: TransitEvent.h:33
Setups a signal handler to handle fatal signals.
Definition: BackendManager.h:28
Definition: LoggerBase.h:39
std::variant< std::monostate, std::atomic< bool > *, double > event_payload
A unique ptr to save space as these fields not always used.
Definition: TransitEvent.h:272