Closed bellekci closed 6 years ago
One thing I've observed with the first method (print c-string) I cannot print empty strings. I get weird characters instead.
The first method (lit) is to log string literals or any other type of string that is guaranteed to outlive the logger thread destruction. That method is very lightweight as it just passes a pointer to the queue.
What is happening is that your "std::string" goes out of scope before the logger thread has processed the entry, so it prints garbage.
To pass a string reference counting would be necessary. This is implementable but I decided to cut the complexity just there.
You need to use the second method, "deep_copy", which embeds the string in the same log entry (the logger just does one internal allocation on an intrusive linked list and copies memory contiguosly).
If you are satisfied with the answer we can close this.
Thanks for the detailed explanation. Long story short, I better use deep_copy then.
Yes, you can close the issue.
Which way is better?
or
log_debug("Example string log: {}", mal::deep_copy(str));
Thanks in advance!