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

Unified Diff: base/syslog_logging.cc

Issue 2530163002: Make the name of the event source for SYSLOG configurable. (Closed)
Patch Set: Remove NOTREACHED and log suffix. Created 4 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
« 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..087b4fd4543195d14bc38b040e58ec5314436f39 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,21 @@ 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. If you see this happening most probably
+ // you are using SYSLOG before you called SetEventSourceName.
+ if (g_event_source_name == nullptr)
+ 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 +79,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