9 #include "quill/core/Attributes.h" 10 #include "quill/core/Common.h" 11 #include "quill/core/LogLevel.h" 15 #include <string_view> 34 LogWithRuntimeMetadataDeepCopy,
35 LogWithRuntimeMetadataHybridCopy,
36 LogWithRuntimeMetadataShallowCopy,
46 constexpr
MacroMetadata(
char const* source_location,
char const* caller_function,
47 char const* message_format,
char const* tags, LogLevel log_level, Event event) noexcept
48 : _source_location(source_location),
49 _caller_function(caller_function),
50 _message_format(message_format),
52 _colon_separator_pos(_calc_colon_separator_pos()),
53 _file_name_pos(_calc_file_name_pos()),
54 _log_level(log_level),
59 QUILL_NODISCARD
char const* source_location()
const noexcept {
return _source_location; }
61 QUILL_NODISCARD
char const* caller_function()
const noexcept {
return _caller_function; }
63 QUILL_NODISCARD
char const* message_format()
const noexcept {
return _message_format; }
65 QUILL_NODISCARD
char const* line()
const noexcept
67 if (QUILL_UNLIKELY(_source_location[_colon_separator_pos] ==
'\0'))
69 return _source_location + _colon_separator_pos;
72 return _source_location + _colon_separator_pos + 1;
75 QUILL_NODISCARD std::string_view full_path()
const noexcept
77 return std::string_view{_source_location, _colon_separator_pos};
80 QUILL_NODISCARD std::string_view file_name()
const noexcept
82 return std::string_view{_source_location + _file_name_pos,
83 static_cast<size_t>(_colon_separator_pos - _file_name_pos)};
86 QUILL_NODISCARD
char const* short_source_location()
const noexcept
88 return _source_location + _file_name_pos;
91 QUILL_NODISCARD LogLevel log_level()
const noexcept {
return _log_level; }
93 QUILL_NODISCARD
char const* tags()
const noexcept {
return _tags; }
95 QUILL_NODISCARD constexpr
bool has_named_args()
const noexcept
97 return contains_named_args(_message_format);
100 QUILL_NODISCARD Event event()
const noexcept {
return _event; }
103 QUILL_NODISCARD
static constexpr
bool contains_named_args(std::string_view fmt) noexcept
106 bool found_named_arg{
false};
109 while (pos < fmt.length())
114 if (pos >= fmt.length())
120 auto const fc = fmt[pos];
129 uint32_t char_cnt{0};
130 while (pos < fmt.length())
135 if (pos >= fmt.length())
156 if ((char_cnt != 0) && ((fc >=
'a' && fc <= 'z') || (fc >=
'A' && fc <=
'Z') || (fc ==
'_')))
158 found_named_arg =
true;
165 return found_named_arg;
170 QUILL_NODISCARD constexpr uint16_t _calc_file_name_pos()
const noexcept
172 char const* source_location = _source_location;
173 char const* file = source_location;
174 while (*source_location)
176 char cur = *source_location++;
177 if (cur ==
'/' || cur == detail::PATH_PREFERRED_SEPARATOR)
179 file = source_location;
182 return static_cast<uint16_t
>(file - _source_location);
186 QUILL_NODISCARD constexpr uint16_t _calc_colon_separator_pos()
const noexcept
190 while (_source_location[length] !=
'\0')
195 for (
size_t i = length; i > 0; --i)
197 if (_source_location[i - 1] ==
':')
199 return static_cast<uint16_t
>(i - 1);
203 return static_cast<uint16_t
>(length);
207 char const* _source_location{
nullptr};
208 char const* _caller_function{
nullptr};
209 char const* _message_format{
nullptr};
210 char const* _tags{
nullptr};
211 uint16_t _colon_separator_pos{0};
212 uint16_t _file_name_pos{0};
213 LogLevel _log_level{LogLevel::None};
214 Event _event{Event::None};
220 "Size of MacroMetadata exceeds the cache line size");
constexpr size_t QUILL_CACHE_LINE_SIZE
Cache line constants.
Definition: Common.h:67