<div dir="ltr">If you use the fmt library it would only require one extra temporary string to be constructed and it works trivially with something like phosphor logging.<div><br></div><div>log<level::INFO>(fmt::format("My error: {}", filename));</div><div><br></div><div>It also has the advantage of understanding basic c++ types like std::strings and std::string_views.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 1, 2020 at 8:33 PM 郁雷 <<a href="mailto:yulei.sh@bytedance.com">yulei.sh@bytedance.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> ---<br>
> ## Don't require `-o verbose` for systemd journal MESSAGE field context<br>
> The MESSAGE field of a systemd journal entry should be self describing and not<br>
> rely on additional structured log data. For example when the MESSAGE field<br>
> references a filesystem path, the path should appear in the MESSAGE field.<br>
> When the MESSAGE field references a failed system call, the system call and the<br>
> return value should appear in the MESSAGE field. This keeps the journal<br>
> informative and useful for casual journal users. Note that it is perfectly<br>
> acceptible to add (duplicate) structured log entry values for the data that<br>
> appears in MESSAGE. This guideline only prescribes that the data _not_ be<br>
> omitted from the MESSAGE field value.<br>
><br>
<br>
I have a bit concern about this. The existing phosphor-logging API<br>
does not support this well.<br>
Specifically, it does not support the "printf" way to generate a<br>
string with the variables to log.<br>
So previously we typically put the variables in entries.<br>
I do agree that logging the variables in the MESSAGE field is much better.<br>
But to encourage such logging, the logging API should be enhanced to<br>
support the "printf" way.<br>
E.g.<br>
log<level::INFO>("Something is wrong: %s:%d", xx, xxx);<br>
is much better than:<br>
std::string to_log = xxx; // generate the message manually<br>
log<level::INFO>(to_log);<br>
<br>
Otherwise, it's really not convenient to write such logging code.<br>
</blockquote></div>