John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 1 | #ifndef AOS_UTIL_DEATH_TEST_LOG_IMPLEMENTATION_H_ |
| 2 | #define AOS_UTIL_DEATH_TEST_LOG_IMPLEMENTATION_H_ |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 3 | |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 4 | #include <cstdlib> |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 5 | |
Austin Schuh | ad9e5eb | 2021-11-19 20:33:55 -0800 | [diff] [blame] | 6 | #include "aos/logging/context.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 7 | #include "aos/logging/implementations.h" |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 8 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 9 | namespace aos::util { |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 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. |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 14 | class DeathTestLogImplementation |
| 15 | : public logging::HandleMessageLogImplementation { |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 16 | public: |
Austin Schuh | ad9e5eb | 2021-11-19 20:33:55 -0800 | [diff] [blame] | 17 | std::string_view MyName() override { |
| 18 | logging::internal::Context *context = logging::internal::Context::Get(); |
| 19 | return context->MyName(); |
| 20 | } |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 21 | virtual void HandleMessage(const logging::LogMessage &message) override { |
| 22 | if (message.level == FATAL) { |
| 23 | logging::internal::PrintMessage(stderr, message); |
| 24 | abort(); |
| 25 | } |
| 26 | } |
| 27 | }; |
| 28 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 29 | } // namespace aos::util |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 30 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 31 | #endif // AOS_UTIL_DEATH_TEST_LOG_IMPLEMENTATION_H_ |