Commit 2ee7489b authored by Zhengxu Chen's avatar Zhengxu Chen Committed by Facebook GitHub Bot

Don't append space delimiter when context string is empty.

Summary:
Currently when context string is "", we will still append whitespace to log header. This looks like:
```
I0729 17:36:53.249270 438847 ThriftServerEventHandler.cpp:21 ] Sampling servers
```
which is less readable compared to
```
I0729 17:36:53.249270 438847 ThriftServerEventHandler.cpp:21] Sampling servers
```
. Ideally empty context string should mean "there's no context string to report here", so we should not put an extra delimiter in such case.

Reviewed By: simpkins

Differential Revision: D22835634

fbshipit-source-id: c7fc6de4036050eac3b7d16bf607c637d1394c44
parent f9f5da22
...@@ -662,9 +662,12 @@ std::string LoggerDB::ContextCallbackList::getContextString() const { ...@@ -662,9 +662,12 @@ std::string LoggerDB::ContextCallbackList::getContextString() const {
std::string ret; std::string ret;
callbacks->forEach([&](const auto& callback) { callbacks->forEach([&](const auto& callback) {
ret += ' ';
try { try {
ret += callback(); auto ctx = callback();
if (ctx.empty()) {
return;
}
folly::toAppend(' ', std::move(ctx), &ret);
} catch (const std::exception& e) { } catch (const std::exception& e) {
folly::toAppend("[error:", folly::exceptionStr(e), "]", &ret); folly::toAppend("[error:", folly::exceptionStr(e), "]", &ret);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment