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

Unified Diff: chromeos/device_event_log.cc

Issue 773703002: Generalize network_event_log -> device_event_log (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years 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
Index: chromeos/device_event_log.cc
diff --git a/chromeos/device_event_log.cc b/chromeos/device_event_log.cc
new file mode 100644
index 0000000000000000000000000000000000000000..07bdef2d35b0d47422017787c558d8d9cbf4a005
--- /dev/null
+++ b/chromeos/device_event_log.cc
@@ -0,0 +1,94 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
Ben Chan 2014/12/02 21:42:53 drop (c) http://www.chromium.org/developers/codin
stevenjb 2014/12/03 00:16:03 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/device_event_log.h"
+
+#include <string>
+
+#include "chromeos/device_event_log_impl.h"
+
+namespace chromeos {
+
+namespace device_event_log {
+
+namespace {
+
+const size_t kDefaultMaxEntries = 4000;
+
+DeviceEventLogImpl* g_device_event_log = NULL;
+
+} // namespace
+
+const LogLevel kDefaultLogLevel = LOG_LEVEL_EVENT;
+
+void Initialize(size_t max_entries) {
+ if (max_entries == 0)
+ max_entries = kDefaultMaxEntries;
+ if (g_device_event_log)
jennyz 2014/12/02 22:16:08 Is it normal to re-initialize g_device_event_log w
stevenjb 2014/12/03 00:16:03 I don't know about "normal", but it is harmless. I
jennyz 2014/12/03 19:12:43 Acknowledged.
+ delete g_device_event_log; // resets log
+ g_device_event_log = new DeviceEventLogImpl(max_entries);
+}
+
+void Shutdown() {
+ delete g_device_event_log;
+ g_device_event_log = NULL;
+}
+
+bool IsInitialized() {
+ return g_device_event_log != NULL;
+}
+
+void AddEntry(const char* file,
+ int line,
+ LogType type,
+ LogLevel level,
+ const std::string& event) {
+ if (g_device_event_log) {
+ g_device_event_log->AddEntry(file, line, type, level, event);
+ } else {
+ DeviceEventLogImpl::SendToVLogOrErrorLog(file, line, type, level, event);
+ }
+}
+
+void AddEntryWithDescription(const char* file,
+ int line,
+ LogType type,
+ LogLevel level,
+ const std::string& event,
+ const std::string& desc) {
+ std::string event_with_desc = event;
+ if (!desc.empty())
+ event_with_desc += ": " + desc;
+ AddEntry(file, line, type, level, event_with_desc);
+}
+
+std::string GetAsString(StringOrder order,
+ const std::string& format,
+ LogType log_type,
+ LogLevel max_level,
+ size_t max_events) {
+ if (!g_device_event_log)
+ return "DeviceEventLog not initialized.";
+ return g_device_event_log->GetAsString(order, format, log_type, max_level,
+ max_events);
+}
+
+namespace internal {
+
+DeviceEventLogInstance::DeviceEventLogInstance(const char* file,
+ int line,
+ device_event_log::LogType type,
+ device_event_log::LogLevel level)
+ : file_(file), line_(line), type_(type), level_(level) {
+}
+
+DeviceEventLogInstance::~DeviceEventLogInstance() {
+ device_event_log::AddEntry(file_, line_, type_, level_, stream_.str());
+}
+
+} // namespace internal
+
+} // namespace device_event_log
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698