Go to the documentation of this file.
9 #ifndef EAGINE_LOGGING_SYSLOG_BACKEND_HPP
10 #define EAGINE_LOGGING_SYSLOG_BACKEND_HPP
12 #include "../config/platform.hpp"
13 #include "../flat_map.hpp"
14 #include "../memory/default_alloc.hpp"
15 #include "../memory/span_algo.hpp"
20 #include <sys/types.h>
27 template <
typename Lockable = std::mutex>
28 class syslog_log_backend :
public logger_backend {
31 : _min_severity{min_severity} {
35 LOG_CONS | LOG_NDELAY | LOG_PID,
41 -> logger_backend*
final {
42 if(severity >= _min_severity) {
48 auto allocator() noexcept -> memory::shared_byte_allocator final {
49 return memory::default_byte_allocator();
65 EAGINE_MAYBE_UNUSED(src);
67 const auto idn{src.name()};
71 :
"%8lx|%10.*s|name=%s, desc=%s",
72 static_cast<unsigned long>(inst),
87 auto& msg = _new_message();
93 :
"%8lx|%10.*s|%10.*s|");
99 auto& msg = _get_message();
100 const auto aidv = arg.value();
102 for(
auto [idx, idv] : msg.arg_idx) {
109 msg.arg_map[aidv].assign(value);
111 msg.format.append(
", ");
112 msg.format.append(arg.name().view());
113 msg.format.append(
"=");
114 msg.format.append(value);
122 do_add_arg(arg, value.name().view());
129 temp.append(value.class_().name().view());
131 temp.append(value.method().name().view());
132 do_add_arg(arg, temp);
141 using std::to_string;
142 do_add_arg(arg, to_string(value));
147 using std::to_string;
148 do_add_arg(arg, to_string(value));
152 using std::to_string;
153 do_add_arg(arg, to_string(value));
159 using std::to_string;
160 do_add_arg(arg, to_string(value));
166 std::chrono::duration<float> value) noexcept
final {
167 using std::to_string;
168 std::string temp(to_string(value.count()));
170 do_add_arg(arg, temp);
175 using std::to_string;
176 do_add_arg(arg, value);
181 void finish_message() noexcept final {
182 _do_log(_get_message());
186 void finish_log() noexcept final {
192 void log_chart_sample(
196 float) noexcept
final {}
199 Lockable _lockable{};
202 struct _message_state {
207 flat_map<std::size_t, identifier_t> arg_idx;
208 flat_map<identifier_t, std::string> arg_map;
209 std::size_t arg_count{0};
212 _message_state _the_message{};
214 auto _new_message() noexcept -> auto& {
216 _the_message.arg_count = 0;
217 for(
auto& [idx, idv] : _the_message.arg_idx) {
218 EAGINE_MAYBE_UNUSED(idx);
224 auto _get_message() noexcept -> auto& {
228 void _del_message() noexcept {
253 EAGINE_MAYBE_UNUSED(severity);
260 msg.format.append(prev);
263 msg.arg_idx[msg.arg_count++] =
265 msg.format.append(
"%s");
269 msg.format.append(
format);
272 template <std::size_t... I>
273 void _do_log_I(_message_state& msg, std::index_sequence<I...>) {
274 const auto source_name = msg.source.name();
275 const auto tag_name = msg.tag ? msg.tag.name().str() : std::string();
279 static_cast<unsigned long>(msg.instance),
280 int(source_name.size()),
282 int(tag_name.size()),
284 msg.arg_map[msg.arg_idx[I]].c_str()...);
287 template <std::
size_t N>
288 auto _do_log_N(_message_state& msg) ->
bool {
289 if constexpr(N > 0) {
290 if(_do_log_N<N - 1>(msg)) {
294 if(msg.arg_count == N) {
295 _do_log_I(msg, std::make_index_sequence<N>());
301 void _do_log(_message_state& msg) {
308 #endif // EAGINE_LOGGING_SYSLOG_BACKEND_HPP
static constexpr auto find_position(basic_span< T1, P1, S1 > spn, basic_span< T2, P2, S2 > what) noexcept -> optionally_valid< S1 >
Finds the position of the first occurrence of what in a span.
Definition: span_algo.hpp:260
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
#define EAGINE_ID(NAME)
Macro for constructing instances of eagine::identifier.
Definition: identifier.hpp:353
@ backtrace
Backtracing log entries (the lowest severity).
static constexpr auto c_str(memory::basic_span< C, P, S > s) -> std::enable_if_t< std::is_convertible_v< memory::basic_span< C, P, S >, basic_string_span< C, P, S >>, basic_c_str< C, P, S >>
Functions that construct a basic_c_str from a basic_string_span.
Definition: string_span.hpp:226
Common code is placed in this namespace.
Definition: eagine.hpp:21
std::uintptr_t logger_instance_id
Logger object instance id type.
Definition: backend.hpp:56
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
basic_block< true > const_block
Alias for const byte memory span.
Definition: block.hpp:32
@ warning
Warning log entries, indicating potential problems.
@ info
Informational log entries.
static constexpr auto head(basic_span< T, P, S > s, L l) noexcept -> basic_span< T, P, S >
Returns the first l elements from the front of a span.
Definition: span_algo.hpp:99
@ error
Error log entries, indicating serious problems.
static auto format(std::string &&fmt_str) noexcept -> format_string_and_list< 0 >
Function taking a format string, returning an object for variable specification.
Definition: str_format.hpp:118
static constexpr auto skip(basic_span< T, P, S > s, L l) noexcept -> basic_span< T, P, S >
Skips a specified count of elements from the front of a span.
Definition: span_algo.hpp:60
@ debug
Debug log entries.
@ fatal
Fatal error log entries, indicating problem requiring termination.
@ trace
Trace log entries.
log_event_severity
Log event severity enumeration.
Definition: severity.hpp:18
@ stat
Statistic log entries.
basic_identifier< 10, 6, default_identifier_char_set, identifier_t > identifier
Default identifier type used throughout the project.
Definition: identifier.hpp:346