logging: add LoggerDB::updateConfig() and resetConfig()
[folly.git] / folly / experimental / logging / test / TestLogHandler.h
index 6fa2173377a9be9aa27840b8bbcad9bbdad3f618..c799d316de02d43c47a997795d928c1f1a46b249 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <folly/experimental/logging/LogHandler.h>
 #include <folly/experimental/logging/LogHandlerConfig.h>
+#include <folly/experimental/logging/LogHandlerFactory.h>
 #include <folly/experimental/logging/LogMessage.h>
 
 namespace folly {
@@ -34,6 +35,8 @@ namespace folly {
  */
 class TestLogHandler : public LogHandler {
  public:
+  using Options = LogHandlerConfig::Options;
+
   TestLogHandler() : config_{"test"} {}
   explicit TestLogHandler(LogHandlerConfig config)
       : config_{std::move(config)} {}
@@ -60,10 +63,36 @@ class TestLogHandler : public LogHandler {
     return config_;
   }
 
- private:
+  void setOptions(const Options& options) {
+    config_.options = options;
+  }
+
+ protected:
   std::vector<std::pair<LogMessage, const LogCategory*>> messages_;
   uint64_t flushCount_{0};
   std::map<std::string, std::string> options_;
   LogHandlerConfig config_;
 };
+
+/**
+ * A LogHandlerFactory to create TestLogHandler objects.
+ */
+class TestLogHandlerFactory : public LogHandlerFactory {
+ public:
+  explicit TestLogHandlerFactory(StringPiece type) : type_{type.str()} {}
+
+  StringPiece getType() const override {
+    return type_;
+  }
+
+  std::shared_ptr<LogHandler> createHandler(const Options& options) override;
+
+  std::shared_ptr<LogHandler> updateHandler(
+      const std::shared_ptr<LogHandler>& existingHandler,
+      const Options& options) override;
+
+ private:
+  std::string type_;
+};
+
 } // namespace folly