quill
BackendOptions.h
1 
7 #pragma once
8 
9 #include "quill/core/Attributes.h"
10 #include "quill/core/LogLevel.h"
11 
12 #include <array>
13 #include <chrono>
14 #include <cstdint>
15 #include <cstdio>
16 #include <functional>
17 #include <string>
18 #include <vector>
19 
20 #if defined(__MINGW32__)
21  #include <iostream>
22 #endif
23 
24 QUILL_BEGIN_NAMESPACE
25 
26 namespace detail
27 {
28 inline void backend_options_default_error_notifier(std::string const& error_message)
29 {
30 #if !defined(__MINGW32__)
31  std::fprintf(stderr, "%s\n", error_message.data());
32 #else
33  // fprintf crashes on mingw gcc 13 for unknown reason
34  std::cerr << error_message.data() << "\n";
35 #endif
36 }
37 
38 inline bool backend_options_default_check_printable_char(char c) noexcept
39 {
40  return (c >= ' ' && c <= '~') || (c == '\n') || (c == '\t') || (c == '\r');
41 }
42 } // namespace detail
43 
44 QUILL_BEGIN_EXPORT
45 
52 {
53  BackendOptions() = default;
54 
59  std::string thread_name = "QuillBackend";
60 
67  bool enable_yield_when_idle = false;
68 
72  std::chrono::nanoseconds sleep_duration = std::chrono::microseconds{100};
73 
81  uint32_t transit_event_buffer_initial_capacity = 256;
82 
98  size_t transit_events_soft_limit = 8192;
99 
115  size_t transit_events_hard_limit = 65'536;
116 
165  std::chrono::microseconds log_timestamp_ordering_grace_period{5};
166 
189  bool ensure_monotonic_output_timestamps = false;
190 
206  bool wait_for_queues_to_empty_before_exit = true;
207 
220  std::vector<uint16_t> cpu_affinity;
221 
241  std::function<void(std::string const&)> error_notifier{detail::backend_options_default_error_notifier};
242 
249  std::function<void()> backend_worker_on_poll_begin = {};
250 
257  std::function<void()> backend_worker_on_poll_end = {};
258 
272  std::chrono::milliseconds rdtsc_resync_interval = std::chrono::milliseconds{500};
273 
289  std::chrono::milliseconds sink_min_flush_interval = std::chrono::milliseconds{200};
290 
304  std::function<bool(char c)> check_printable_char{detail::backend_options_default_check_printable_char};
305 
311  std::array<std::string, LogLevelCount> log_level_descriptions = {
312  "TRACE_L3", "TRACE_L2", "TRACE_L1", "DEBUG", "INFO", "NOTICE",
313  "WARNING", "ERROR", "CRITICAL", "BACKTRACE", "NONE"};
314 
321  std::array<std::string, LogLevelCount> log_level_short_codes = {"T3", "T2", "T1", "D", "I", "N",
322  "W", "E", "C", "BT", "_"};
323 
340  std::string mdc_format_pattern = " [{}: {}, ]";
341 
362  bool check_backend_singleton_instance = true;
363 };
364 
365 QUILL_END_EXPORT
366 
367 QUILL_END_NAMESPACE
Setups a signal handler to handle fatal signals.
Definition: BackendManager.h:28
Configuration options for the backend.
Definition: BackendOptions.h:51