blob: f6ec4d6e1191b3abaa54b1777bcd101b4eb0c295 [file] [log] [blame]
Austin Schuh47aabde2020-10-10 17:46:37 -07001#include <sys/resource.h>
2#include <sys/time.h>
3
James Kuszmaul38735e82019-12-07 16:42:06 -08004#include "aos/configuration.h"
5#include "aos/events/logging/logger.h"
6#include "aos/events/shm_event_loop.h"
7#include "aos/init.h"
Brian Silvermand90905f2020-09-23 14:42:56 -07008#include "aos/logging/log_namer.h"
James Kuszmaul38735e82019-12-07 16:42:06 -08009#include "gflags/gflags.h"
10#include "glog/logging.h"
11
James Kuszmaul38735e82019-12-07 16:42:06 -080012DEFINE_string(config, "config.json", "Config file to use.");
13
14int main(int argc, char *argv[]) {
15 gflags::SetUsageMessage(
16 "This program provides a simple logger binary that logs all SHMEM data "
17 "directly to a file specified at the command line. It does not manage "
18 "filenames, so it will just crash if you attempt to overwrite an "
19 "existing file, and the user must specify the logfile manually at the "
20 "command line.");
21 aos::InitGoogle(&argc, &argv);
22
23 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
24 aos::configuration::ReadConfig(FLAGS_config);
25
26 aos::ShmEventLoop event_loop(&config.message());
27
Sabina Davisa3d08412020-02-23 17:47:28 -080028 std::unique_ptr<aos::logger::LogNamer> log_namer;
29 if (event_loop.node() == nullptr) {
Austin Schuh2f8fd752020-09-01 22:38:28 -070030 log_namer = std::make_unique<aos::logger::LocalLogNamer>(
31 aos::logging::GetLogName("fbs_log"), event_loop.node());
Sabina Davisa3d08412020-02-23 17:47:28 -080032 } else {
33 log_namer = std::make_unique<aos::logger::MultiNodeLogNamer>(
Austin Schuhe715eae2020-10-10 15:39:30 -070034 absl::StrCat(aos::logging::GetLogName("fbs_log"), "/"),
35 event_loop.configuration(), event_loop.node());
Sabina Davisa3d08412020-02-23 17:47:28 -080036 }
Austin Schuhcde938c2020-02-02 17:30:07 -080037
Brian Silverman1f345222020-09-24 21:14:48 -070038 aos::logger::Logger logger(&event_loop);
Austin Schuh47aabde2020-10-10 17:46:37 -070039 event_loop.OnRun([&log_namer, &logger]() {
40 errno = 0;
41 setpriority(PRIO_PROCESS, 0, -20);
42 PCHECK(errno == 0) << ": Renicing to -20 failed";
43 logger.StartLogging(std::move(log_namer));
44 });
James Kuszmaul38735e82019-12-07 16:42:06 -080045
46 event_loop.Run();
47
Austin Schuh2f8fd752020-09-01 22:38:28 -070048 LOG(INFO) << "Shutting down";
49
James Kuszmaul38735e82019-12-07 16:42:06 -080050 return 0;
51}