James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 1 | #include "aos/configuration.h" |
| 2 | #include "aos/events/logging/logger.h" |
| 3 | #include "aos/events/shm_event_loop.h" |
| 4 | #include "aos/init.h" |
Brian Silverman | d90905f | 2020-09-23 14:42:56 -0700 | [diff] [blame] | 5 | #include "aos/logging/log_namer.h" |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 6 | #include "gflags/gflags.h" |
| 7 | #include "glog/logging.h" |
| 8 | |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 9 | DEFINE_string(config, "config.json", "Config file to use."); |
| 10 | |
| 11 | int main(int argc, char *argv[]) { |
| 12 | gflags::SetUsageMessage( |
| 13 | "This program provides a simple logger binary that logs all SHMEM data " |
| 14 | "directly to a file specified at the command line. It does not manage " |
| 15 | "filenames, so it will just crash if you attempt to overwrite an " |
| 16 | "existing file, and the user must specify the logfile manually at the " |
| 17 | "command line."); |
| 18 | aos::InitGoogle(&argc, &argv); |
| 19 | |
| 20 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 21 | aos::configuration::ReadConfig(FLAGS_config); |
| 22 | |
| 23 | aos::ShmEventLoop event_loop(&config.message()); |
| 24 | |
Sabina Davis | a3d0841 | 2020-02-23 17:47:28 -0800 | [diff] [blame] | 25 | std::unique_ptr<aos::logger::DetachedBufferWriter> writer; |
| 26 | std::unique_ptr<aos::logger::LogNamer> log_namer; |
| 27 | if (event_loop.node() == nullptr) { |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 28 | log_namer = std::make_unique<aos::logger::LocalLogNamer>( |
| 29 | aos::logging::GetLogName("fbs_log"), event_loop.node()); |
Sabina Davis | a3d0841 | 2020-02-23 17:47:28 -0800 | [diff] [blame] | 30 | } else { |
| 31 | log_namer = std::make_unique<aos::logger::MultiNodeLogNamer>( |
| 32 | aos::logging::GetLogName("fbs_log"), event_loop.configuration(), |
| 33 | event_loop.node()); |
| 34 | } |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 35 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame^] | 36 | aos::logger::Logger logger(&event_loop); |
| 37 | event_loop.OnRun( |
| 38 | [&log_namer, &logger]() { logger.StartLogging(std::move(log_namer)); }); |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 39 | |
| 40 | event_loop.Run(); |
| 41 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 42 | LOG(INFO) << "Shutting down"; |
| 43 | |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 44 | return 0; |
| 45 | } |