blob: 48c9dcb7e1882685f3447294939d4f53e928b74e [file] [log] [blame]
Sarah Newmana7e87932022-04-11 15:00:03 -07001#include "aos/logging/dynamic_logging.h"
Austin Schuh60e77942022-05-16 17:48:24 -07002
Stephan Pleines0960c262024-05-31 20:29:24 -07003#include <ostream>
4#include <string_view>
5
6#include "flatbuffers/string.h"
Sarah Newmana7e87932022-04-11 15:00:03 -07007#include "glog/logging.h"
8
Stephan Pleinesf63bde82024-01-13 15:59:33 -08009namespace aos::logging {
Sarah Newmana7e87932022-04-11 15:00:03 -070010
11DynamicLogging::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
23void 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 Pleinesf63bde82024-01-13 15:59:33 -080037} // namespace aos::logging