Sarah Newman | a7e8793 | 2022-04-11 15:00:03 -0700 | [diff] [blame] | 1 | #include "aos/logging/dynamic_logging.h" |
Austin Schuh | 60e7794 | 2022-05-16 17:48:24 -0700 | [diff] [blame] | 2 | |
Stephan Pleines | 0960c26 | 2024-05-31 20:29:24 -0700 | [diff] [blame] | 3 | #include <ostream> |
| 4 | #include <string_view> |
| 5 | |
| 6 | #include "flatbuffers/string.h" |
Sarah Newman | a7e8793 | 2022-04-11 15:00:03 -0700 | [diff] [blame] | 7 | #include "glog/logging.h" |
| 8 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 9 | namespace aos::logging { |
Sarah Newman | a7e8793 | 2022-04-11 15:00:03 -0700 | [diff] [blame] | 10 | |
| 11 | DynamicLogging::DynamicLogging(aos::EventLoop *event_loop) |
| 12 | : application_name_(event_loop->name()) { |
| 13 | if (event_loop->GetChannel<DynamicLogCommand>("/aos") == nullptr) { |
| 14 | LOG(WARNING) << "Disabling dynamic logger because the DynamicLogCommand " |
| 15 | "channel is not configured."; |
| 16 | } else { |
| 17 | event_loop->MakeWatcher("/aos", [this](const DynamicLogCommand &cmd) { |
| 18 | HandleDynamicLogCommand(cmd); |
| 19 | }); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | void DynamicLogging::HandleDynamicLogCommand(const DynamicLogCommand &command) { |
| 24 | // For now we expect someone to do an aos_send at the command line, thecommand |
| 25 | // may be malformed. |
| 26 | if (!command.has_name() || !command.has_vlog_level()) return; |
| 27 | |
| 28 | if (command.name()->string_view() != application_name_) { |
| 29 | return; |
| 30 | } |
| 31 | if (command.vlog_level() < 0) { |
| 32 | return; |
| 33 | } |
| 34 | FLAGS_v = command.vlog_level(); |
| 35 | } |
| 36 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 37 | } // namespace aos::logging |