summaryrefslogtreecommitdiff
path: root/src/mongo/logger
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2017-05-25 17:51:17 -0400
committersamantharitter <samantha.ritter@10gen.com>2017-05-30 11:22:57 -0400
commitfad590916a30ff34dc8c3b37afcfffa2c4e5c8bc (patch)
treec57610dde742c1e17316b756c9ccb4215ce58db6 /src/mongo/logger
parent6a11fc05770306b5d660b21f339cba110d6d67d4 (diff)
downloadmongo-fad590916a30ff34dc8c3b37afcfffa2c4e5c8bc.tar.gz
SERVER-29152 Do not cache logging ostream in threadlocal when in other thread-specific contexts
Diffstat (limited to 'src/mongo/logger')
-rw-r--r--src/mongo/logger/logstream_builder.cpp12
-rw-r--r--src/mongo/logger/logstream_builder.h9
2 files changed, 16 insertions, 5 deletions
diff --git a/src/mongo/logger/logstream_builder.cpp b/src/mongo/logger/logstream_builder.cpp
index af055be3120..2378558bd4a 100644
--- a/src/mongo/logger/logstream_builder.cpp
+++ b/src/mongo/logger/logstream_builder.cpp
@@ -80,12 +80,14 @@ LogstreamBuilder::LogstreamBuilder(MessageLogDomain* domain,
LogstreamBuilder::LogstreamBuilder(MessageLogDomain* domain,
StringData contextName,
LogSeverity severity,
- LogComponent component)
+ LogComponent component,
+ bool shouldCache)
: _domain(domain),
_contextName(contextName.toString()),
_severity(std::move(severity)),
_component(std::move(component)),
- _tee(nullptr) {}
+ _tee(nullptr),
+ _shouldCache(shouldCache) {}
LogstreamBuilder::LogstreamBuilder(logger::MessageLogDomain* domain,
StringData contextName,
@@ -110,7 +112,8 @@ LogstreamBuilder::~LogstreamBuilder() {
_tee->write(_os->str());
}
_os->str("");
- if (isThreadOstreamCacheInitialized && !threadOstreamCache.getMake()->get()) {
+ if (_shouldCache && isThreadOstreamCacheInitialized &&
+ !threadOstreamCache.getMake()->get()) {
*threadOstreamCache.get() = std::move(_os);
}
}
@@ -124,7 +127,8 @@ void LogstreamBuilder::operator<<(Tee* tee) {
void LogstreamBuilder::makeStream() {
if (!_os) {
- if (isThreadOstreamCacheInitialized && threadOstreamCache.getMake()->get()) {
+ if (_shouldCache && isThreadOstreamCacheInitialized &&
+ threadOstreamCache.getMake()->get()) {
_os = std::move(*threadOstreamCache.get());
} else {
_os = stdx::make_unique<std::ostringstream>();
diff --git a/src/mongo/logger/logstream_builder.h b/src/mongo/logger/logstream_builder.h
index 1dac8462564..7c1cd62882f 100644
--- a/src/mongo/logger/logstream_builder.h
+++ b/src/mongo/logger/logstream_builder.h
@@ -73,11 +73,17 @@ public:
* "contextName" is a short name of the thread or other context.
* "severity" is the logging severity of the message.
* "component" is the primary log component of the message.
+ *
+ * By default, this class will create one ostream per thread, and it
+ * will cache that object in a threadlocal and reuse it for subsequent
+ * logs messages. Set "shouldCache" to false to create a new ostream
+ * for each instance of this class rather than cacheing.
*/
LogstreamBuilder(MessageLogDomain* domain,
StringData contextName,
LogSeverity severity,
- LogComponent component);
+ LogComponent component,
+ bool shouldCache = true);
/**
* Deprecated.
@@ -225,6 +231,7 @@ private:
std::unique_ptr<std::ostringstream> _os;
Tee* _tee;
bool _isTruncatable = true;
+ bool _shouldCache;
};