Skip to content

Variable length string logging #211

Answered by odygrd
hkpackage asked this question in Q&A
Discussion options

You must be logged in to vote

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.

#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],…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by odygrd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants