proxygen
|
#include <StandardLogHandler.h>
Public Member Functions | |
StandardLogHandler (LogHandlerConfig config, std::shared_ptr< LogFormatter > formatter, std::shared_ptr< LogWriter > writer, LogLevel syncLevel=LogLevel::MAX_LEVEL) | |
~StandardLogHandler () | |
const std::shared_ptr< LogFormatter > & | getFormatter () const |
const std::shared_ptr< LogWriter > & | getWriter () const |
LogLevel | getLevel () const |
void | setLevel (LogLevel level) |
void | handleMessage (const LogMessage &message, const LogCategory *handlerCategory) override |
void | flush () override |
LogHandlerConfig | getConfig () const override |
![]() | |
virtual | ~LogHandler ()=default |
Private Attributes | |
std::atomic< LogLevel > | level_ {LogLevel::NONE} |
std::atomic< LogLevel > | syncLevel_ {LogLevel::MAX_LEVEL} |
const std::shared_ptr< LogFormatter > | formatter_ |
const std::shared_ptr< LogWriter > | writer_ |
const LogHandlerConfig | config_ |
StandardLogHandler is a LogHandler implementation that uses a LogFormatter class to serialize the LogMessage into a string, and then gives it to a LogWriter object.
This basically is a simple glue class that helps chain together configurable LogFormatter and LogWriter objects.
StandardLogHandler also supports ignoring messages less than a specific LogLevel. By default it processes all messages.
Definition at line 41 of file StandardLogHandler.h.
folly::StandardLogHandler::StandardLogHandler | ( | LogHandlerConfig | config, |
std::shared_ptr< LogFormatter > | formatter, | ||
std::shared_ptr< LogWriter > | writer, | ||
LogLevel | syncLevel = LogLevel::MAX_LEVEL |
||
) |
Definition at line 24 of file StandardLogHandler.cpp.
References config, config_, folly::gen::move, and writer_.
folly::StandardLogHandler::~StandardLogHandler | ( | ) |
Definition at line 34 of file StandardLogHandler.cpp.
|
overridevirtual |
Block until all messages that have already been sent to this LogHandler have been processed.
For LogHandlers that perform asynchronous processing of log messages, this ensures that messages already sent to this handler have finished being processed.
Other threads may still call handleMessage() while flush() is running. handleMessage() calls that did not complete before the flush() call started will not necessarily be processed by the flush call.
Implements folly::LogHandler.
Definition at line 48 of file StandardLogHandler.cpp.
References writer_.
Referenced by handleMessage(), and setLevel().
|
overridevirtual |
Return a LogHandlerConfig object describing the configuration of this LogHandler.
Implements folly::LogHandler.
Definition at line 52 of file StandardLogHandler.cpp.
References config_.
Referenced by setLevel().
|
inline |
Get the LogFormatter used by this handler.
Definition at line 53 of file StandardLogHandler.h.
References formatter_.
|
inline |
Get the handler's current LogLevel.
Messages less than this LogLevel will be ignored. This defaults to LogLevel::NONE when the handler is constructed.
Definition at line 70 of file StandardLogHandler.h.
References level_.
Referenced by handleMessage().
|
inline |
Get the LogWriter used by this handler.
Definition at line 60 of file StandardLogHandler.h.
References writer_.
|
overridevirtual |
handleMessage() is called when a log message is processed by a LogCategory that this handler is attached to.
This must be implemented by LogHandler subclasses.
handleMessage() will always be invoked from the thread that logged the message. LogMessage::getThreadID() contains the thread ID, but the LogHandler can also include any other thread-local state they desire, and this will always be data for the thread that originated the log message.
message | The LogMessage objet. |
handlerCategory | The LogCategory that invoked handleMessage(). This is the category that this LogHandler is attached to. Note that this may be different than the category that this message was originally logged at. message->getCategory() returns the category of the log message. |
Implements folly::LogHandler.
Definition at line 36 of file StandardLogHandler.cpp.
References flush(), formatter_, getLevel(), folly::LogMessage::getLevel(), syncLevel_, and writer_.
Referenced by setLevel(), and TEST().
|
inline |
Set the handler's current LogLevel.
Messages less than this LogLevel will be ignored.
Definition at line 79 of file StandardLogHandler.h.
References flush(), getConfig(), handleMessage(), and level_.
Referenced by TEST().
|
private |
Definition at line 103 of file StandardLogHandler.h.
Referenced by getConfig(), and StandardLogHandler().
|
private |
Definition at line 101 of file StandardLogHandler.h.
Referenced by getFormatter(), and handleMessage().
|
private |
Definition at line 92 of file StandardLogHandler.h.
Referenced by getLevel(), and setLevel().
|
private |
Definition at line 93 of file StandardLogHandler.h.
Referenced by handleMessage().
|
private |
Definition at line 102 of file StandardLogHandler.h.
Referenced by flush(), getWriter(), handleMessage(), and StandardLogHandler().