blob: f061c61610eb80ba04605bc35bb1830fa3f47ef9 [file] [log] [blame]
John Park33858a32018-09-28 23:05:48 -07001#ifndef AOS_UTIL_DEATH_TEST_LOG_IMPLEMENTATION_H_
2#define AOS_UTIL_DEATH_TEST_LOG_IMPLEMENTATION_H_
Brian Silverman01be0002014-05-10 15:44:38 -07003
4#include <stdlib.h>
5
John Park33858a32018-09-28 23:05:48 -07006#include "aos/logging/implementations.h"
Brian Silverman01be0002014-05-10 15:44:38 -07007
8namespace aos {
9namespace util {
10
11// Prints all FATAL messages to stderr and then abort(3)s before the regular
12// stuff can print out anything else. Ignores all other messages.
13// This is useful in death tests that expect a LOG(FATAL) to cause the death.
14class DeathTestLogImplementation : public logging::HandleMessageLogImplementation {
15 public:
16 virtual void HandleMessage(const logging::LogMessage &message) override {
17 if (message.level == FATAL) {
18 logging::internal::PrintMessage(stderr, message);
19 abort();
20 }
21 }
22};
23
24} // namespace util
25} // namespace aos
26
John Park33858a32018-09-28 23:05:48 -070027#endif // AOS_UTIL_DEATH_TEST_LOG_IMPLEMENTATION_H_