-
How to log a variable length string?
|
Beta Was this translation helpful? Give feedback.
Answered by
odygrd
Dec 15, 2022
Replies: 1 comment
-
hey, It is not directly supported. However, you can use Even when you use #include "quill/Quill.h"
#include <string_view>
#include <string>
constexpr std::string_view var_str(char const* str, size_t len)
{
return std::string_view {str, len};
}
int main()
{
quill::start();
char buffer[10];
size_t constexpr str_len = 5;
std::memcpy(&buffer[0], "hello", str_len);
LOG_INFO(quill::get_logger(), "variable string {}", var_str(&buffer[0], str_len));
LOG_INFO(quill::get_logger(), "variable string {}", std::string_view{&buffer[0], str_len});
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
odygrd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey,
It is not directly supported. However, you can use
std::string_view
for that.Even when you use
std::string_view
, a deep copy of the string is taken on the hot path and pushed into a queue to get logged later, so even if your original buffer goes out of scope at any point, the correct string will still be printed.