OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 "mojo/logging/init_logging.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/logging.h" | |
9 | |
10 namespace mojo { | |
11 namespace { | |
12 | |
13 ::logging::LoggingDestination DetermineLogMode( | |
14 const base::CommandLine& command_line) { | |
15 // only use OutputDebugString in debug mode | |
16 #if defined(NDEBUG) | |
17 bool enable_logging = false; | |
18 const char* kInvertLoggingSwitch = "enable-logging"; | |
19 #else | |
20 bool enable_logging = true; | |
21 const char* kInvertLoggingSwitch = "disable-logging"; | |
22 #endif | |
23 const ::logging::LoggingDestination kDefaultLoggingMode = | |
24 ::logging::LOG_TO_SYSTEM_DEBUG_LOG; | |
25 | |
26 if (command_line.HasSwitch(kInvertLoggingSwitch)) | |
27 enable_logging = !enable_logging; | |
28 | |
29 return enable_logging ? kDefaultLoggingMode : ::logging::LOG_NONE; | |
30 } | |
31 | |
32 } // namespace | |
33 | |
34 void InitLogging() { | |
35 ::logging::LoggingSettings settings; | |
36 settings.logging_dest = DetermineLogMode( | |
37 *base::CommandLine::ForCurrentProcess()); | |
38 ::logging::InitLogging(settings); | |
39 | |
40 // we want process and thread IDs because we have a lot of things running | |
41 ::logging::SetLogItems(true, // enable_process_id | |
42 true, // enable_thread_id | |
43 true, // enable_timestamp | |
44 false); // enable_tickcount | |
45 } | |
46 | |
47 } // namespace mojo | |
OLD | NEW |