diff options
Diffstat (limited to 'src/mongo/logger/log_domain.h')
-rw-r--r-- | src/mongo/logger/log_domain.h | 182 |
1 files changed, 94 insertions, 88 deletions
diff --git a/src/mongo/logger/log_domain.h b/src/mongo/logger/log_domain.h index 0313985b2f1..47ecde761c2 100644 --- a/src/mongo/logger/log_domain.h +++ b/src/mongo/logger/log_domain.h @@ -38,101 +38,107 @@ namespace mongo { namespace logger { +/** + * Logging domain for events of type E. + * + * A logging domain consists of a set of Appenders. + * + * TODO: The severity doesn't seem to apply for auditing, maybe it only belongs on the + * MessageLogManager? We don't really have multiple tunable logging domains, right now. Other + * than the global domain, shouldLog doesn't matter. + * + * Usage: Configure the log domain in a single threaded context, using attachAppender, + * detachAppender and clearAppenders(). The domain takes ownership of any attached appender, + * returning an AppenderHandle for each attached appender. That handle may be used later to + * detach the appender, causing the domain to release ownership of it. Mostly, this + * attach/detach behavior is useful in testing, since you do not want to change the appenders of + * a domain that is currently receiving append() calls. + * + * Once you've configured the domain, call append() from potentially many threads, to add log + * messages. + */ +template <typename E> +class LogDomain { + MONGO_DISALLOW_COPYING(LogDomain); + +public: + typedef E Event; + typedef Appender<Event> EventAppender; + /** - * Logging domain for events of type E. - * - * A logging domain consists of a set of Appenders. - * - * TODO: The severity doesn't seem to apply for auditing, maybe it only belongs on the - * MessageLogManager? We don't really have multiple tunable logging domains, right now. Other - * than the global domain, shouldLog doesn't matter. - * - * Usage: Configure the log domain in a single threaded context, using attachAppender, - * detachAppender and clearAppenders(). The domain takes ownership of any attached appender, - * returning an AppenderHandle for each attached appender. That handle may be used later to - * detach the appender, causing the domain to release ownership of it. Mostly, this - * attach/detach behavior is useful in testing, since you do not want to change the appenders of - * a domain that is currently receiving append() calls. - * - * Once you've configured the domain, call append() from potentially many threads, to add log - * messages. + * Opaque handle returned by attachAppender(), which can be subsequently passed to + * detachAppender() to detach an appender from an instance of LogDomain. */ - template <typename E> - class LogDomain { - MONGO_DISALLOW_COPYING(LogDomain); + class AppenderHandle { + friend class LogDomain; + public: - typedef E Event; - typedef Appender<Event> EventAppender; - - /** - * Opaque handle returned by attachAppender(), which can be subsequently passed to - * detachAppender() to detach an appender from an instance of LogDomain. - */ - class AppenderHandle { - friend class LogDomain; - public: - AppenderHandle() {} - - private: - explicit AppenderHandle(size_t index) : _index(index) {} - - size_t _index; - }; - - // TODO(schwerin): Replace with unique_ptr in C++11. - typedef std::unique_ptr<EventAppender> AppenderAutoPtr; - - LogDomain(); - ~LogDomain(); - - /** - * Receives an event for logging, calling append(event) on all attached appenders. - * - * 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. - */ - Status append(const Event& event); - - /** - * 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 - // caller. - // - - /** - * Attaches "appender" to this domain, taking ownership of it. Returns a handle that may be - * used later to detach this appender. - */ - AppenderHandle attachAppender(AppenderAutoPtr appender); - - /** - * Detaches the appender referenced by "handle" from this domain, releasing ownership of it. - * Returns an unique_ptr to the handler to the caller, who is now responsible for its - * deletion. Caller should consider "handle" is invalid after this call. - */ - AppenderAutoPtr detachAppender(AppenderHandle handle); - - /** - * Destroy all attached appenders, invalidating all handles. - */ - void clearAppenders(); + AppenderHandle() {} private: - typedef std::vector<EventAppender*> AppenderVector; + explicit AppenderHandle(size_t index) : _index(index) {} - AppenderVector _appenders; - bool _abortOnFailure; + size_t _index; }; + // TODO(schwerin): Replace with unique_ptr in C++11. + typedef std::unique_ptr<EventAppender> AppenderAutoPtr; + + LogDomain(); + ~LogDomain(); + + /** + * Receives an event for logging, calling append(event) on all attached appenders. + * + * 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. + */ + Status append(const Event& event); + + /** + * 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 + // caller. + // + + /** + * Attaches "appender" to this domain, taking ownership of it. Returns a handle that may be + * used later to detach this appender. + */ + AppenderHandle attachAppender(AppenderAutoPtr appender); + + /** + * Detaches the appender referenced by "handle" from this domain, releasing ownership of it. + * Returns an unique_ptr to the handler to the caller, who is now responsible for its + * deletion. Caller should consider "handle" is invalid after this call. + */ + AppenderAutoPtr detachAppender(AppenderHandle handle); + + /** + * Destroy all attached appenders, invalidating all handles. + */ + void clearAppenders(); + +private: + typedef std::vector<EventAppender*> AppenderVector; + + AppenderVector _appenders; + bool _abortOnFailure; +}; + } // namespace logger } // namespace mongo |