Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1522)

Unified Diff: mojo/logging/init_logging.cc

Issue 1304893008: Adds a common way to initialize logging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/logging/init_logging.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/logging/init_logging.cc
diff --git a/mojo/logging/init_logging.cc b/mojo/logging/init_logging.cc
new file mode 100644
index 0000000000000000000000000000000000000000..89e98d6d39d760fbc5a121bb198c6cee008f0788
--- /dev/null
+++ b/mojo/logging/init_logging.cc
@@ -0,0 +1,49 @@
+// 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 {
+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 logging
+} // namespace mojo
« no previous file with comments | « mojo/logging/init_logging.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698