9 #include "quill/core/Attributes.h" 10 #include "quill/core/Common.h" 11 #include "quill/core/LogLevel.h" 15 #include <string_view> 32 LogWithRuntimeMetadataDeepCopy,
33 LogWithRuntimeMetadataHybridCopy,
34 LogWithRuntimeMetadataShallowCopy,
40 constexpr
MacroMetadata(
char const* source_location,
char const* caller_function,
41 char const* message_format,
char const* tags, LogLevel log_level, Event event) noexcept
42 : _source_location(source_location),
43 _caller_function(caller_function),
44 _message_format(message_format),
46 _colon_separator_pos(_calc_colon_separator_pos()),
47 _file_name_pos(_calc_file_name_pos()),
48 _log_level(log_level),
53 QUILL_NODISCARD
char const* source_location()
const noexcept {
return _source_location; }
55 QUILL_NODISCARD
char const* caller_function()
const noexcept {
return _caller_function; }
57 QUILL_NODISCARD
char const* message_format()
const noexcept {
return _message_format; }
59 QUILL_NODISCARD
char const* line()
const noexcept
61 return _source_location + _colon_separator_pos + 1;
64 QUILL_NODISCARD std::string_view full_path()
const noexcept
66 return std::string_view{_source_location, _colon_separator_pos};
69 QUILL_NODISCARD std::string_view file_name()
const noexcept
71 return std::string_view{_source_location + _file_name_pos,
72 static_cast<size_t>(_colon_separator_pos - _file_name_pos)};
75 QUILL_NODISCARD
char const* short_source_location()
const noexcept
77 return _source_location + _file_name_pos;
80 QUILL_NODISCARD LogLevel log_level()
const noexcept {
return _log_level; }
82 QUILL_NODISCARD
char const* tags()
const noexcept {
return _tags; }
84 QUILL_NODISCARD constexpr
bool has_named_args()
const noexcept
86 return _contains_named_args(_message_format);
89 QUILL_NODISCARD Event event()
const noexcept {
return _event; }
92 QUILL_NODISCARD
static constexpr
bool _contains_named_args(std::string_view fmt) noexcept
95 bool found_named_arg{
false};
98 while (pos < fmt.length())
103 if (pos >= fmt.length())
109 auto const fc = fmt[pos];
118 uint32_t char_cnt{0};
119 while (pos < fmt.length())
124 if (pos >= fmt.length())
145 if ((char_cnt != 0) && ((fc >=
'a' && fc <= 'z') || (fc >=
'A' && fc <=
'Z')))
147 found_named_arg =
true;
153 return found_named_arg;
158 QUILL_NODISCARD constexpr uint16_t _calc_file_name_pos()
const noexcept
160 char const* source_location = _source_location;
161 char const* file = source_location;
162 while (*source_location)
164 char cur = *source_location++;
165 if (cur ==
'/' || cur == detail::PATH_PREFERRED_SEPARATOR)
167 file = source_location;
170 return static_cast<uint16_t
>(file - _source_location);
174 QUILL_NODISCARD constexpr uint16_t _calc_colon_separator_pos()
const noexcept
176 std::string_view
const source_loc{_source_location};
177 auto const separator_index = source_loc.rfind(
':');
178 return static_cast<uint16_t
>(separator_index);
182 char const* _source_location{
nullptr};
183 char const* _caller_function{
nullptr};
184 char const* _message_format{
nullptr};
185 char const* _tags{
nullptr};
186 uint16_t _colon_separator_pos{0};
187 uint16_t _file_name_pos{0};
188 LogLevel _log_level{LogLevel::None};
189 Event _event{Event::None};
192 static_assert(
sizeof(
MacroMetadata) <= detail::QUILL_CACHE_LINE_SIZE,
193 "Size of MacroMetadata exceeds the cache line size");