-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cc
59 lines (49 loc) · 1.98 KB
/
main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include <vector>
#include <base/command_line.h>
#include <base/logging.h>
#include <base/task/single_thread_task_executor.h>
#include <brillo/flag_helper.h>
#include <brillo/syslog_logging.h>
#include "croslog/config.h"
#include "croslog/viewer_journal.h"
#include "croslog/viewer_plaintext.h"
int main(int argc, char* argv[]) {
// The following method defines the command line arguments and initializes
// the brillo's command line parser. See the code for detail.
croslog::Config config;
bool parse_result = config.ParseCommandLineArgs(argc, argv);
// The method above (|croslog::Config::ParseCommandLineArgs|) initializes the
// command line, so this code needs to be placed after that.
base::CommandLine* const command_line =
base::CommandLine::ForCurrentProcess();
if (!parse_result) {
command_line->AppendSwitch("help");
// Calling this method shows the command line usage.
brillo::FlagHelper::GetInstance()->UpdateFlagValues();
return 1;
}
// Configure the log destination. This should be placed before any code which
// potentially write logs.
int log_flags = brillo::kLogToStderr;
// if the stdin is not tty, send logs to syslog as well.
if (!isatty(0) || command_line->HasSwitch("send-syslog"))
log_flags |= brillo::kLogToSyslog;
brillo::InitLog(log_flags);
switch (config.source) {
case croslog::SourceMode::JOURNAL_LOG:
croslog::ViewerJournal viewer;
return viewer.Run(config) ? 0 : 1;
case croslog::SourceMode::PLAINTEXT_LOG: {
// Do not use them directly.
base::SingleThreadTaskExecutor task_executor(base::MessagePumpType::IO);
base::AtExitManager at_exit_manager_;
// TODO(yoshiki): Implement the reader of plaintext logs.
croslog::ViewerPlaintext viewer(config);
return viewer.Run() ? 0 : 1;
}
}
}