blob: 1bc74f26c9fb25ae6fa78ebdbe372a7522182084 [file] [log] [blame]
James Kuszmaul38735e82019-12-07 16:42:06 -08001#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 Silvermand90905f2020-09-23 14:42:56 -07005#include "aos/logging/log_namer.h"
James Kuszmaul38735e82019-12-07 16:42:06 -08006#include "gflags/gflags.h"
7#include "glog/logging.h"
8
James Kuszmaul38735e82019-12-07 16:42:06 -08009DEFINE_string(config, "config.json", "Config file to use.");
10
11int 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 Davisa3d08412020-02-23 17:47:28 -080025 std::unique_ptr<aos::logger::LogNamer> log_namer;
26 if (event_loop.node() == nullptr) {
Austin Schuh2f8fd752020-09-01 22:38:28 -070027 log_namer = std::make_unique<aos::logger::LocalLogNamer>(
28 aos::logging::GetLogName("fbs_log"), event_loop.node());
Sabina Davisa3d08412020-02-23 17:47:28 -080029 } else {
30 log_namer = std::make_unique<aos::logger::MultiNodeLogNamer>(
Austin Schuhe715eae2020-10-10 15:39:30 -070031 absl::StrCat(aos::logging::GetLogName("fbs_log"), "/"),
32 event_loop.configuration(), event_loop.node());
Sabina Davisa3d08412020-02-23 17:47:28 -080033 }
Austin Schuhcde938c2020-02-02 17:30:07 -080034
Brian Silverman1f345222020-09-24 21:14:48 -070035 aos::logger::Logger logger(&event_loop);
36 event_loop.OnRun(
37 [&log_namer, &logger]() { logger.StartLogging(std::move(log_namer)); });
James Kuszmaul38735e82019-12-07 16:42:06 -080038
39 event_loop.Run();
40
Austin Schuh2f8fd752020-09-01 22:38:28 -070041 LOG(INFO) << "Shutting down";
42
James Kuszmaul38735e82019-12-07 16:42:06 -080043 return 0;
44}