event_logger_test.cc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #include <string>
  6. #include "logging/event_logger.h"
  7. #include "test_util/testharness.h"
  8. namespace ROCKSDB_NAMESPACE {
  9. class EventLoggerTest : public testing::Test {};
  10. class StringLogger : public Logger {
  11. public:
  12. using Logger::Logv;
  13. void Logv(const char* format, va_list ap) override {
  14. vsnprintf(buffer_, sizeof(buffer_), format, ap);
  15. }
  16. char* buffer() { return buffer_; }
  17. private:
  18. char buffer_[1000];
  19. };
  20. TEST_F(EventLoggerTest, SimpleTest) {
  21. StringLogger logger;
  22. EventLogger event_logger(&logger);
  23. event_logger.Log() << "id" << 5 << "event"
  24. << "just_testing";
  25. std::string output(logger.buffer());
  26. ASSERT_TRUE(output.find("\"event\": \"just_testing\"") != std::string::npos);
  27. ASSERT_TRUE(output.find("\"id\": 5") != std::string::npos);
  28. ASSERT_TRUE(output.find("\"time_micros\"") != std::string::npos);
  29. }
  30. } // namespace ROCKSDB_NAMESPACE
  31. int main(int argc, char** argv) {
  32. ::testing::InitGoogleTest(&argc, argv);
  33. return RUN_ALL_TESTS();
  34. }