summaryrefslogtreecommitdiff
path: root/src/mongo/logger
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2013-11-25 09:48:42 -0500
committerEric Milkie <milkie@10gen.com>2013-11-25 09:49:08 -0500
commit7fdecdbe6901c23faf9febd1d52368218375877f (patch)
treeaf7d1b0518376f666e8ba34a99856da3dab0acaa /src/mongo/logger
parent95586f19acca1258a819930e206100efb1ce4000 (diff)
downloadmongo-7fdecdbe6901c23faf9febd1d52368218375877f.tar.gz
SERVER-11028 new abortOnFailure property of log domains
Diffstat (limited to 'src/mongo/logger')
-rw-r--r--src/mongo/logger/log_domain-impl.h21
-rw-r--r--src/mongo/logger/log_domain.h17
2 files changed, 30 insertions, 8 deletions
diff --git a/src/mongo/logger/log_domain-impl.h b/src/mongo/logger/log_domain-impl.h
index cb9e0605f8d..8fd8486c6d5 100644
--- a/src/mongo/logger/log_domain-impl.h
+++ b/src/mongo/logger/log_domain-impl.h
@@ -15,9 +15,11 @@
#pragma once
-#include "mongo/logger/message_log_domain.h"
-
#include <algorithm>
+#include <cstdlib>
+
+#include "mongo/base/status.h"
+#include "mongo/logger/message_log_domain.h"
/*
* Implementation of LogDomain<E>. Include this in cpp files to instantiate new LogDomain types.
@@ -28,7 +30,9 @@ namespace mongo {
namespace logger {
template <typename E>
- LogDomain<E>::LogDomain() : _minimumLoggedSeverity(LogSeverity::Log()) {}
+ LogDomain<E>::LogDomain()
+ : _minimumLoggedSeverity(LogSeverity::Log()), _abortOnFailure(false)
+ {}
template <typename E>
LogDomain<E>::~LogDomain() {
@@ -36,14 +40,21 @@ namespace logger {
}
template <typename E>
- void LogDomain<E>::append(const E& event) {
+ Status LogDomain<E>::append(const E& event) {
for (typename AppenderVector::const_iterator iter = _appenders.begin();
iter != _appenders.end(); ++iter) {
if (*iter) {
- (*iter)->append(event);
+ Status status = (*iter)->append(event);
+ if (!status.isOK()) {
+ if (_abortOnFailure) {
+ ::abort();
+ }
+ return status;
+ }
}
}
+ return Status::OK();
}
template <typename E>
diff --git a/src/mongo/logger/log_domain.h b/src/mongo/logger/log_domain.h
index b1f6dcb81f3..940958d7f8b 100644
--- a/src/mongo/logger/log_domain.h
+++ b/src/mongo/logger/log_domain.h
@@ -77,10 +77,11 @@ namespace logger {
/**
* Receives an event for logging, calling append(event) on all attached appenders.
*
- * TODO(schwerin): Should we return failed statuses somehow? vector<AppenderHandle, Status>
- * for failed appends, e.g.?
+ * If any appender fails, the behavior is determined by the abortOnFailure flag:
+ * *If abortOnFailure is set, ::abort() is immediately called.
+ * *If abortOnFailure is not set, the error is returned and no further appenders are called.
*/
- void append(const Event& event);
+ Status append(const Event& event);
/**
* Predicate that answers the question, "Should I, the caller, append to you, the log
@@ -98,6 +99,15 @@ namespace logger {
*/
void setMinimumLoggedSeverity(LogSeverity severity) { _minimumLoggedSeverity = severity; }
+ /**
+ * Gets the state of the abortOnFailure flag.
+ */
+ bool getAbortOnFailure() const { return _abortOnFailure; }
+
+ /**
+ * Sets the state of the abortOnFailure flag.
+ */
+ void setAbortOnFailure(bool abortOnFailure) { _abortOnFailure = abortOnFailure; }
//
// Configuration methods. Must be synchronized with each other and calls to "append" by the
@@ -127,6 +137,7 @@ namespace logger {
LogSeverity _minimumLoggedSeverity;
AppenderVector _appenders;
+ bool _abortOnFailure;
};
} // namespace logger