Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
logchecker.h
Go to the documentation of this file.
1 
18 #ifndef ION_BASE_LOGCHECKER_H_
19 #define ION_BASE_LOGCHECKER_H_
20 
21 #include <sstream>
22 #include <string>
23 #include <vector>
24 
25 #include "ion/base/logging.h"
26 
27 namespace ion {
28 namespace base {
29 
55 class ION_API LogChecker : public port::LogEntryWriter {
56  public:
58  LogChecker();
59 
62  ~LogChecker() override;
63 
65  void Write(port::LogSeverity severity, const std::string& message)
66  override;
67 
74  bool HasMessage(const std::string& severity, const std::string& substring);
75 
80  bool HasNoMessage(const std::string& severity, const std::string& substring);
81 
84  bool HasAnyMessages() const {
85  return !GetLogString().empty();
86  }
87 
92  const std::vector<std::string> GetAllMessages();
93 
95  void ClearLog() {
96  stream_.str("");
97  }
98 
100  const std::string GetLogString() const {
101  return stream_.str();
102  }
103 
104  private:
105  port::LogEntryWriter* previous_writer_;
106  std::ostringstream stream_;
107 };
108 
109 } // namespace base
110 } // namespace ion
111 
112 #endif // ION_BASE_LOGCHECKER_H_
Abstract class which can be overridden to integrate Ion logging with other logging systems...
Definition: logging.h:36
bool HasAnyMessages() const
Returns true if any messages were logged since the instance was constructed or since the last call to...
Definition: logchecker.h:84
void ClearLog()
Clears any messages that may be in the log.
Definition: logchecker.h:95
LogSeverity
Definition: logging.h:26
const std::string GetLogString() const
Returns a string containing all current logged messages.
Definition: logchecker.h:100
Copyright 2016 Google Inc.
The LogChecker class can be used inside unit tests to trap all log output and verify that it matches ...
Definition: logchecker.h:55