blob: 14891b88a0033f5d13f2451d87e92bb69606a0d8 [file] [log] [blame]
// 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 =
if (!parse_result) {
// Calling this method shows the command line usage.
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;
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;