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

Unified Diff: base/syslog_logging.cc

Issue 2530163002: Make the name of the event source for SYSLOG configurable. (Closed)
Patch Set: Fix unit test. Created 4 years, 1 month 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 | « base/syslog_logging.h ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/syslog_logging.cc
diff --git a/base/syslog_logging.cc b/base/syslog_logging.cc
index 1cd545910a967a6f52f5a138136bceb8be6782fd..17b750ded14bcd5de0894aac9d83d8b579f4c416 100644
--- a/base/syslog_logging.cc
+++ b/base/syslog_logging.cc
@@ -6,6 +6,8 @@
#include "base/syslog_logging.h"
#if defined(OS_WIN)
+#include "base/bind.h"
+#include "base/callback_helpers.h"
#include "base/win/eventlog_messages.h"
#include <windows.h>
@@ -19,6 +21,18 @@
namespace logging {
+#if defined(OS_WIN)
+
+namespace {
+std::string* g_event_source_name = nullptr;
+}
+
+void SetEventSourceName(const std::string& name) {
+ DCHECK_EQ(nullptr, g_event_source_name);
+ g_event_source_name = new std::string(name);
+}
+#endif // defined(OS_WIN)
+
EventLogMessage::EventLogMessage(const char* file,
int line,
LogSeverity severity)
@@ -27,13 +41,23 @@ EventLogMessage::EventLogMessage(const char* file,
EventLogMessage::~EventLogMessage() {
#if defined(OS_WIN)
- const char kEventSource[] = "chrome";
- HANDLE event_log_handle = RegisterEventSourceA(NULL, kEventSource);
+ // If g_event_source_name is nullptr (which it is per default) SYSLOG will
+ // degrade gracefully to regular LOG with an extra error suffix. If you see
Nico 2016/12/02 03:08:41 Is this useful? Why wouldn't this CHECK(false) ins
pastarmovj 2016/12/02 19:30:59 I see this as a debugging facility for the debiggi
Nico 2016/12/02 20:28:58 History shows that nobody looks at log spam. Eithe
pastarmovj 2016/12/05 08:40:10 Done.
+ // this happening most probably you are using SYSLOG before you called
+ // SetEventSourceName.
+ if (g_event_source_name == nullptr) {
+ stream() << " !!EVENTLOG SOURCE NAME NOT SET!!";
+ return;
+ }
+ HANDLE event_log_handle =
+ RegisterEventSourceA(NULL, g_event_source_name->c_str());
if (event_log_handle == NULL) {
stream() << " !!NOT ADDED TO EVENTLOG!!";
return;
}
+ base::ScopedClosureRunner auto_deregister(
+ base::Bind(base::IgnoreResult(&DeregisterEventSource), event_log_handle));
std::string message(log_message_.str());
WORD log_type = EVENTLOG_ERROR_TYPE;
switch (log_message_.severity()) {
@@ -57,7 +81,6 @@ EventLogMessage::~EventLogMessage() {
MSG_LOG_MESSAGE, NULL, 1, 0, strings, NULL)) {
stream() << " !!NOT ADDED TO EVENTLOG!!";
}
- DeregisterEventSource(event_log_handle);
#elif defined(OS_LINUX)
const char kEventSource[] = "chrome";
openlog(kEventSource, LOG_NOWAIT | LOG_PID, LOG_USER);
« no previous file with comments | « base/syslog_logging.h ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698