Go to the documentation of this file.
9 #ifndef EAGINE_LOGGING_ENTRY_HPP
10 #define EAGINE_LOGGING_ENTRY_HPP
12 #include "../bitfield.hpp"
13 #include "../branch_predict.hpp"
14 #include "../memory/object_storage.hpp"
15 #include "../message_id.hpp"
16 #include "../valid_if/decl.hpp"
22 static inline auto adapt_log_entry_arg(
identifier name, logger_backend* value) {
23 return [name, value](logger_backend& backend) {
25 backend.add_identifier(
26 name,
EAGINE_ID(LogBkEndId), value->type_id());
28 backend.add_nothing(name,
EAGINE_ID(LogBkEndId));
33 template <
typename T,
typename = std::enable_if_t<has_enumerator_mapping_v<T>>>
34 static constexpr
auto adapt_log_entry_arg(
identifier name, T value) {
35 return [=](logger_backend& backend) {
36 backend.add_string(name,
EAGINE_ID(
enum), enumerator_name(value));
40 template <
typename T,
typename = std::enable_if_t<has_enumerator_mapping_v<T>>>
41 static constexpr
auto adapt_log_entry_arg(
identifier name, bitfield<T> bf) {
42 return [=](logger_backend& backend) {
43 auto func = [&backend, name, bf](
const auto&
info) {
44 if(bf.has(
static_cast<T
>(
info.value))) {
48 for_each_enumerator(func, type_identity<T>{});
53 struct does_have_log_entry_function;
56 using has_log_entry_function_t =
typename does_have_log_entry_function<T>::type;
59 constexpr
const bool has_log_entry_function_v =
60 has_log_entry_function_t<T>::value;
76 : _source_id{source_id}
77 , _instance_id{instance_id}
80 , _args{_be_alloc(_backend)}
81 , _severity{severity} {
100 _source_id, _entry_tag, _instance_id, _severity, _format))) {
146 backend.add_message_id(name,
tag, value);
387 return arg(name,
float(value));
411 float max) noexcept ->
auto& {
432 template <
typename R,
typename P>
436 std::chrono::duration<R, P> value) noexcept ->
auto& {
442 std::chrono::duration_cast<std::chrono::duration<float>>(
452 template <
typename R,
typename P>
522 template <
typename Func>
525 _args.add(std::move(
function));
534 template <
typename T>
536 -> std::enable_if_t<has_log_entry_adapter_v<std::decay_t<T>>,
log_entry&> {
538 _args.add(adapt_log_entry_arg(name, std::forward<T>(value)));
548 template <
typename T,
typename P,
typename F>
554 has_log_entry_function_v<std::decay_t<T>> &&
555 has_log_entry_function_v<std::decay_t<F>>,
558 return arg(name,
tag, std::move(opt.value()));
560 return arg(name, std::move(opt.fallback()));
569 template <
typename T,
typename P,
typename F>
573 has_log_entry_function_v<std::decay_t<T>> &&
574 has_log_entry_function_v<std::decay_t<F>>,
581 _entry_tag = entry_tag;
589 logger_backend* _backend{
nullptr};
591 memory::callable_storage<void(logger_backend&)> _args;
594 static auto _be_alloc(logger_backend* backend) noexcept
595 -> memory::shared_byte_allocator {
597 return backend->allocator();
607 template <
typename T>
608 constexpr
auto arg(
identifier, T&&) noexcept ->
auto& {
611 template <
typename T>
620 template <
typename T>
621 constexpr
auto arg(
identifier, span<const T>) noexcept ->
auto& {
625 template <
typename T>
631 template <
typename T,
typename P,
typename F>
637 template <
typename Func>
638 constexpr
auto arg_func(
const Func&) ->
auto& {
642 constexpr
auto tag(
identifier) noexcept ->
auto& {
647 template <
typename T>
648 struct does_have_log_entry_function {
652 typename = decltype(std::declval<log_entry>().arg(
653 std::declval<identifier>(),
654 std::declval<identifier>(),
656 static auto _test(X*) -> std::true_type;
657 static auto _test(...) -> std::false_type;
661 using type = decltype(_test(
static_cast<T*
>(
nullptr)));
670 operator std::ostream&() noexcept {
679 : _source_id{source_id}
680 , _instance_id{instance_id}
682 , _severity{severity} {}
684 stream_log_entry(stream_log_entry&&) =
default;
685 stream_log_entry(
const stream_log_entry&) =
delete;
686 auto operator=(stream_log_entry&&) =
delete;
687 auto operator=(
const stream_log_entry&) =
delete;
689 ~stream_log_entry() noexcept {
691 auto fmt_str(_out.str());
692 if(!fmt_str.empty()) {
709 auto tag(
identifier entry_tag) noexcept ->
auto& {
710 _entry_tag = entry_tag;
715 std::stringstream _out{};
719 logger_backend* _backend{
nullptr};
725 #if !EAGINE_LINK_LIBRARY || defined(EAGINE_IMPLEMENTING_LIBRARY)
726 #include <eagine/logging/entry.inl>
729 #endif // EAGINE_LOGGING_ENTRY_HPP
auto arg(identifier name, identifier tag, std::uint64_t value) noexcept -> auto &
Adds a new message argument with 64-bit unsigned integer value.
Definition: entry.hpp:266
virtual void add_string(identifier arg, identifier tag, string_view value) noexcept=0
Add argument with string value.
auto arg(identifier name, identifier tag, valid_if< T, P > opt, F fbck) noexcept -> std::enable_if_t< has_log_entry_function_v< std::decay_t< T >> &&has_log_entry_function_v< std::decay_t< F >>, log_entry & >
Adds a new message argument with valid_if or fallback value.
Definition: entry.hpp:571
auto arg(identifier name, span< const std::uint64_t > values) noexcept -> auto &
Adds a new message argument with 64-bit unsigned integer span.
Definition: entry.hpp:291
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
auto arg(identifier name, identifier tag, std::int16_t value) noexcept -> auto &
Adds a new message argument with 16-bit signed integer value.
Definition: entry.hpp:232
auto arg(identifier name, identifier tag, float min, float value, float max) noexcept -> auto &
Adds a new message argument with floating-point value.
Definition: entry.hpp:406
Common code is placed in this namespace.
Definition: eagine.hpp:21
auto arg(identifier name, identifier tag, string_view value) noexcept -> auto &
Adds a new message argument with string value.
Definition: entry.hpp:462
log_entry(identifier source_id, logger_instance_id instance_id, log_event_severity severity, string_view format, logger_backend *backend) noexcept
Constructor.
Definition: entry.hpp:70
auto arg(identifier name, std::uint64_t value) noexcept -> auto &
Adds a new message argument with 64-bit unsigned integer value.
Definition: entry.hpp:279
static auto either_or(valid_if< T, P > vi, F f) noexcept(noexcept(valid_if< T, P >(std::declval< valid_if< T, P > && >())) &&noexcept(F(std::declval< F && >()))) -> valid_if_or_fallback< T, P, F >
Constructor function for valid_if_or_fallback.
Definition: decl.hpp:290
auto arg(identifier name, std::chrono::duration< R, P > value) noexcept -> auto &
Adds a new message argument with time duration value.
Definition: entry.hpp:453
virtual void finish_message() noexcept=0
Finishes the current logging message.
std::uintptr_t logger_instance_id
Logger object instance id type.
Definition: backend.hpp:56
auto tag(identifier entry_tag) noexcept -> auto &
Adds an optional tag to this log entry.
Definition: entry.hpp:580
@ info
Informational log entries.
auto arg(identifier name, identifier tag, const std::string &value) noexcept -> auto &
Adds a new message argument with string value.
Definition: entry.hpp:483
auto arg(identifier name, span< const std::int16_t > values) noexcept -> auto &
Adds a new message argument with 16-bit signed integer span.
Definition: entry.hpp:257
auto arg(identifier name, std::int64_t value) noexcept -> auto &
Adds a new message argument with 64-bit signed integer value.
Definition: entry.hpp:176
auto arg(identifier name, double value) noexcept -> auto &
Adds a new message argument with double-precision float value.
Definition: entry.hpp:386
virtual void add_duration(identifier arg, identifier tag, std::chrono::duration< float > value) noexcept=0
Add argument with time duration value.
auto arg_func(Func function) -> auto &
Adds a new message argument adapted by the specified function.
Definition: entry.hpp:523
auto arg(identifier name, identifier tag, std::int64_t value) noexcept -> auto &
Adds a new message argument with 64-bit signed integer value.
Definition: entry.hpp:163
auto arg(identifier name, span< const std::uint16_t > values) noexcept -> auto &
Adds a new message argument with 16-bit unsigned integer span.
Definition: entry.hpp:359
auto operator=(log_entry &&)=delete
Not copy assignable.
auto arg(identifier name, identifier tag, message_id value) noexcept -> auto &
Adds a new message argument with message_id type value.
Definition: entry.hpp:142
auto arg(identifier name, identifier tag, identifier value) noexcept -> auto &
Adds a new message argument with identifier value.
Definition: entry.hpp:121
auto arg(identifier name, T &&value) noexcept -> std::enable_if_t< has_log_entry_adapter_v< std::decay_t< T >>, log_entry & >
Adds a new message argument with adaptable-type value.
Definition: entry.hpp:535
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
auto arg(identifier name, message_id value) noexcept -> auto &
Adds a new message argument with identifier value.
Definition: entry.hpp:155
auto arg(identifier name, identifier tag, std::int32_t value) noexcept -> auto &
Adds a new message argument with 32-bit signed integer value.
Definition: entry.hpp:197
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
auto arg(identifier name, identifier tag, valid_if_or_fallback< T, P, F > &&opt) noexcept -> std::enable_if_t< has_log_entry_function_v< std::decay_t< T >> &&has_log_entry_function_v< std::decay_t< F >>, log_entry & >
Adds a new message argument with valid_if_or_fallback value.
Definition: entry.hpp:549
auto arg(identifier name, std::int32_t value) noexcept -> auto &
Adds a new message argument with 32-bit signed integer value.
Definition: entry.hpp:210
Do-nothing variant of log_entry with compatible API.
Definition: entry.hpp:606
auto arg(identifier name, span< const std::uint32_t > values) noexcept -> auto &
Adds a new message argument with 32-bit unsigned integer span.
Definition: entry.hpp:325
auto arg(identifier name, identifier value) noexcept -> auto &
Adds a new message argument with identifier value.
Definition: entry.hpp:134
~log_entry() noexcept
Destructor. Passed the actual entry to the backend.
Definition: entry.hpp:97
auto arg(identifier name, const std::string &value) noexcept -> auto &
Adds a new message argument with string value.
Definition: entry.hpp:496
virtual void add_identifier(identifier arg, identifier tag, identifier value) noexcept=0
Add argument with identifier value.
auto arg(identifier name, std::uint32_t value) noexcept -> auto &
Adds a new message argument with 32-bit unsigned integer value.
Definition: entry.hpp:313
auto arg(identifier name, identifier tag, float value) noexcept -> auto &
Adds a new message argument with floating-point value.
Definition: entry.hpp:368
auto arg(identifier name, span< const std::int64_t > values) noexcept -> auto &
Adds a new message argument with 64-bit signed integer span.
Definition: entry.hpp:188
auto arg(identifier name, string_view value) noexcept -> auto &
Adds a new message argument with string value.
Definition: entry.hpp:475
auto arg(identifier name, float value) noexcept -> auto &
Adds a new message argument with floating-point value.
Definition: entry.hpp:380
auto arg(identifier name, span< const std::int32_t > values) noexcept -> auto &
Adds a new message argument with 32-bit signed integer span.
Definition: entry.hpp:223
auto arg(identifier name, identifier tag, memory::const_block value) noexcept -> auto &
Adds a new message argument with BLOB value.
Definition: entry.hpp:504
log_event_severity
Log event severity enumeration.
Definition: severity.hpp:18
virtual void add_blob(identifier arg, identifier tag, memory::const_block value) noexcept=0
Add argument with BLOB value.
Interface for logging backend implementations.
Definition: backend.hpp:60
auto arg(identifier name, memory::const_block value) noexcept -> auto &
Adds a new message argument with BLOB value.
Definition: entry.hpp:517
Class representing a single log entry / message.
Definition: entry.hpp:67
virtual void add_unsigned(identifier arg, identifier tag, std::uintmax_t value) noexcept=0
Add argument with unsigned integer value.
Log entry helper containing an istream for creating the log message.
Definition: entry.hpp:667
Class storing two identifier values representing class/method pair.
Definition: message_id.hpp:25
auto set_format(string_view format) noexcept -> auto &
Sets the format string for this log entry.
Definition: entry.hpp:112
auto arg(identifier name, float min, float value, float max) noexcept -> auto &
Adds a new message argument with floating-point value.
Definition: entry.hpp:423
auto arg(identifier name, identifier tag, std::chrono::duration< R, P > value) noexcept -> auto &
Adds a new message argument with time duration value.
Definition: entry.hpp:433
virtual void add_float(identifier arg, identifier tag, float value) noexcept=0
Add argument with floating-point value.
virtual void add_integer(identifier arg, identifier tag, std::intmax_t value) noexcept=0
Add argument with signed integer value.
auto arg(identifier name, span< const float > values) noexcept -> auto &
Adds a new message argument with floating-point span.
Definition: entry.hpp:398
virtual auto begin_message(identifier source, identifier tag, logger_instance_id instance, log_event_severity severity, string_view format) noexcept -> bool=0
Begins a new logging message.
auto arg(identifier name, identifier tag, std::uint32_t value) noexcept -> auto &
Adds a new message argument with 32-bit unsigned integer value.
Definition: entry.hpp:300
auto arg(identifier name, identifier tag, std::uint16_t value) noexcept -> auto &
Adds a new message argument with 16-bit unsigned integer value.
Definition: entry.hpp:334
auto arg(identifier name, std::uint16_t value) noexcept -> auto &
Adds a new message argument with 16-bit unsigned integer value.
Definition: entry.hpp:347
Helper class storing both conditionally valid value and fallback.
Definition: decl.hpp:264
auto arg(identifier name, std::int16_t value) noexcept -> auto &
Adds a new message argument with 16-bit signed integer value.
Definition: entry.hpp:245
basic_identifier< 10, 6, default_identifier_char_set, identifier_t > identifier
Default identifier type used throughout the project.
Definition: identifier.hpp:346