proxygen
folly::TestLogHandler Class Reference

#include <TestLogHandler.h>

Inheritance diagram for folly::TestLogHandler:
folly::LogHandler

Public Types

using Options = LogHandlerConfig::Options
 

Public Member Functions

 TestLogHandler ()
 
 TestLogHandler (LogHandlerConfig config)
 
std::vector< std::pair< LogMessage, const LogCategory * > > & getMessages ()
 
std::vector< std::stringgetMessageValues () const
 
void clearMessages ()
 
void handleMessage (const LogMessage &message, const LogCategory *handlerCategory) override
 
void flush () override
 
uint64_t getFlushCount () const
 
LogHandlerConfig getConfig () const override
 
void setOptions (const Options &options)
 
- Public Member Functions inherited from folly::LogHandler
virtual ~LogHandler ()=default
 

Protected Attributes

std::vector< std::pair< LogMessage, const LogCategory * > > messages_
 
uint64_t flushCount_ {0}
 
std::map< std::string, std::stringoptions_
 
LogHandlerConfig config_
 

Detailed Description

A LogHandler that simply keeps a vector of all LogMessages it receives.

This class is not thread-safe. It is intended to be used in single-threaded tests.

Definition at line 36 of file TestLogHandler.h.

Member Typedef Documentation

Constructor & Destructor Documentation

folly::TestLogHandler::TestLogHandler ( )
inline

Definition at line 40 of file TestLogHandler.h.

40 : config_{"test"} {}
LogHandlerConfig config_
folly::TestLogHandler::TestLogHandler ( LogHandlerConfig  config)
inlineexplicit

Definition at line 41 of file TestLogHandler.h.

References folly::gen::move.

42  : config_{std::move(config)} {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
LogHandlerConfig config_
AHArrayT::Config config

Member Function Documentation

void folly::TestLogHandler::clearMessages ( )
inline

Definition at line 49 of file TestLogHandler.h.

References messages_.

49  {
50  messages_.clear();
51  }
std::vector< std::pair< LogMessage, const LogCategory * > > messages_
void folly::TestLogHandler::flush ( )
inlineoverridevirtual

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 59 of file TestLogHandler.h.

References flushCount_.

59  {
60  ++flushCount_;
61  }
LogHandlerConfig folly::TestLogHandler::getConfig ( ) const
inlineoverridevirtual

Return a LogHandlerConfig object describing the configuration of this LogHandler.

Implements folly::LogHandler.

Definition at line 67 of file TestLogHandler.h.

References config_.

67  {
68  return config_;
69  }
LogHandlerConfig config_
uint64_t folly::TestLogHandler::getFlushCount ( ) const
inline

Definition at line 63 of file TestLogHandler.h.

References flushCount_.

63  {
64  return flushCount_;
65  }
std::vector<std::pair<LogMessage, const LogCategory*> >& folly::TestLogHandler::getMessages ( )
inline

Definition at line 44 of file TestLogHandler.h.

References getMessageValues(), and messages_.

44  {
45  return messages_;
46  }
std::vector< std::pair< LogMessage, const LogCategory * > > messages_
std::vector< std::string > folly::TestLogHandler::getMessageValues ( ) const

Definition at line 22 of file TestLogHandler.cpp.

References messages_, and values().

Referenced by getMessages().

22  {
23  std::vector<std::string> values;
24  values.reserve(messages_.size());
25  for (const auto& msgInfo : messages_) {
26  values.push_back(msgInfo.first.getMessage());
27  }
28  return values;
29 }
std::vector< std::pair< LogMessage, const LogCategory * > > messages_
std::vector< int > values(1'000)
void folly::TestLogHandler::handleMessage ( const LogMessage message,
const LogCategory handlerCategory 
)
inlineoverridevirtual

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.

Parameters
messageThe LogMessage objet.
handlerCategoryThe 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 53 of file TestLogHandler.h.

References messages_.

55  {
56  messages_.emplace_back(message, handlerCategory);
57  }
Definition: test.c:42
std::vector< std::pair< LogMessage, const LogCategory * > > messages_
void folly::TestLogHandler::setOptions ( const Options options)
inline

Definition at line 71 of file TestLogHandler.h.

References config_, and folly::LogHandlerConfig::options.

71  {
72  config_.options = options;
73  }
LogHandlerConfig config_

Member Data Documentation

LogHandlerConfig folly::TestLogHandler::config_
protected

Definition at line 79 of file TestLogHandler.h.

Referenced by getConfig(), and setOptions().

uint64_t folly::TestLogHandler::flushCount_ {0}
protected

Definition at line 77 of file TestLogHandler.h.

Referenced by flush(), and getFlushCount().

std::vector<std::pair<LogMessage, const LogCategory*> > folly::TestLogHandler::messages_
protected

Definition at line 76 of file TestLogHandler.h.

Referenced by clearMessages(), getMessages(), getMessageValues(), and handleMessage().

std::map<std::string, std::string> folly::TestLogHandler::options_
protected

Definition at line 78 of file TestLogHandler.h.


The documentation for this class was generated from the following files: