1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "fuchsia/base/init_logging.h"
6 
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 
10 namespace cr_fuchsia {
11 
12 constexpr char kEnableLogging[] = "enable-logging";
13 constexpr char kLogFile[] = "log-file";
14 
InitLoggingFromCommandLine(const base::CommandLine & command_line)15 bool InitLoggingFromCommandLine(const base::CommandLine& command_line) {
16   logging::LoggingSettings settings;
17   if (command_line.GetSwitchValueASCII(kEnableLogging) == "stderr") {
18     settings.logging_dest = logging::LOG_TO_STDERR;
19   } else {
20     settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
21   }
22   if (command_line.HasSwitch(kLogFile)) {
23     settings.logging_dest |= logging::LOG_TO_FILE;
24     settings.log_file_path = command_line.GetSwitchValueASCII(kLogFile).c_str();
25     settings.delete_old = logging::DELETE_OLD_LOG_FILE;
26   }
27   logging::SetLogItems(true /* Process ID */, true /* Thread ID */,
28                        true /* Timestamp */, false /* Tick count */);
29   return logging::InitLogging(settings);
30 }
31 
32 }  // namespace cr_fuchsia
33