summaryrefslogtreecommitdiff
path: root/chromium/mojo/logging/init_logging.cc
blob: 13e28f88800701c32922f8235899edc0d0ef7a97 (plain)
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
// Copyright 2015 The Chromium 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 "mojo/logging/init_logging.h"

#include "base/command_line.h"
#include "base/logging.h"

namespace mojo {
namespace {

::logging::LoggingDestination DetermineLogMode(
    const base::CommandLine& command_line) {
  // only use OutputDebugString in debug mode
#if defined(NDEBUG)
  bool enable_logging = false;
  const char* kInvertLoggingSwitch = "enable-logging";
#else
  bool enable_logging = true;
  const char* kInvertLoggingSwitch = "disable-logging";
#endif
  const ::logging::LoggingDestination kDefaultLoggingMode =
      ::logging::LOG_TO_SYSTEM_DEBUG_LOG;

  if (command_line.HasSwitch(kInvertLoggingSwitch))
    enable_logging = !enable_logging;

  return enable_logging ? kDefaultLoggingMode : ::logging::LOG_NONE;
}

}  // namespace

void InitLogging() {
  ::logging::LoggingSettings settings;
  settings.logging_dest = DetermineLogMode(
      *base::CommandLine::ForCurrentProcess());
  ::logging::InitLogging(settings);

  // we want process and thread IDs because we have a lot of things running
  ::logging::SetLogItems(true,  // enable_process_id
                         true,  // enable_thread_id
                         true,  // enable_timestamp
                         false);  // enable_tickcount
}

}  // namespace mojo