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 
6 #include <string>
7 
8 #include "logging/event_logger.h"
9 #include "test_util/testharness.h"
10 
11 namespace ROCKSDB_NAMESPACE {
12 
13 class EventLoggerTest : public testing::Test {};
14 
15 class StringLogger : public Logger {
16  public:
17   using Logger::Logv;
Logv(const char * format,va_list ap)18   void Logv(const char* format, va_list ap) override {
19     vsnprintf(buffer_, sizeof(buffer_), format, ap);
20   }
buffer()21   char* buffer() { return buffer_; }
22 
23  private:
24   char buffer_[1000];
25 };
26 
TEST_F(EventLoggerTest,SimpleTest)27 TEST_F(EventLoggerTest, SimpleTest) {
28   StringLogger logger;
29   EventLogger event_logger(&logger);
30   event_logger.Log() << "id" << 5 << "event"
31                      << "just_testing";
32   std::string output(logger.buffer());
33   ASSERT_TRUE(output.find("\"event\": \"just_testing\"") != std::string::npos);
34   ASSERT_TRUE(output.find("\"id\": 5") != std::string::npos);
35   ASSERT_TRUE(output.find("\"time_micros\"") != std::string::npos);
36 }
37 
38 }  // namespace ROCKSDB_NAMESPACE
39 
main(int argc,char ** argv)40 int main(int argc, char** argv) {
41   ::testing::InitGoogleTest(&argc, argv);
42   return RUN_ALL_TESTS();
43 }
44