Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/debug/stack_trace.h" | 5 #include "base/debug/stack_trace.h" |
| 6 #include "base/syslog_logging.h" | 6 #include "base/syslog_logging.h" |
|
grt (UTC plus 2)
2017/06/21 20:26:15
nit: this should be the first include with a blank
proberge
2017/06/21 21:33:39
Done.
| |
| 7 | 7 |
| 8 #if defined(OS_WIN) | 8 #if defined(OS_WIN) |
| 9 #include <stddef.h> | |
|
grt (UTC plus 2)
2017/06/21 20:26:15
why is this needed?
proberge
2017/06/21 21:33:38
I think I was trying to get WORD/DWORD defined. Re
| |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 11 #include "base/win/eventlog_messages.h" | |
| 12 | |
| 13 #include <windows.h> | |
| 14 #elif defined(OS_LINUX) | 12 #elif defined(OS_LINUX) |
| 15 #include <syslog.h> | 13 #include <syslog.h> |
| 16 #endif | 14 #endif |
| 17 | 15 |
| 18 #include <cstring> | 16 #include <cstring> |
|
grt (UTC plus 2)
2017/06/21 20:26:15
this doesn't seem to be used, is it?
proberge
2017/06/21 21:33:38
Done.
| |
| 19 #include <ostream> | 17 #include <ostream> |
| 20 #include <string> | 18 #include <string> |
| 21 | 19 |
| 22 namespace logging { | 20 namespace logging { |
| 23 | 21 |
| 24 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 25 | 23 |
| 26 namespace { | 24 namespace { |
| 27 std::string* g_event_source_name = nullptr; | 25 std::string* g_event_source_name = nullptr; |
|
grt (UTC plus 2)
2017/06/21 20:26:15
now that there's more than one thing in here, plea
proberge
2017/06/21 21:33:38
Done.
| |
| 26 WORD g_category; | |
|
grt (UTC plus 2)
2017/06/21 20:26:15
please zero-initialize these
proberge
2017/06/21 21:33:38
Done.
| |
| 27 DWORD g_event_id; | |
| 28 } | 28 } |
|
grt (UTC plus 2)
2017/06/21 20:26:15
nit:
} // namespace
proberge
2017/06/21 21:33:38
Done.
| |
| 29 | 29 |
| 30 void SetEventSourceName(const std::string& name) { | 30 void SetEventSource(const std::string& name, WORD category, DWORD event_id) { |
| 31 DCHECK_EQ(nullptr, g_event_source_name); | 31 DCHECK_EQ(nullptr, g_event_source_name); |
| 32 g_event_source_name = new std::string(name); | 32 g_event_source_name = new std::string(name); |
| 33 g_category = category; | |
| 34 g_event_id = event_id; | |
| 33 } | 35 } |
| 34 #endif // defined(OS_WIN) | 36 #endif // defined(OS_WIN) |
|
grt (UTC plus 2)
2017/06/21 20:26:15
nit: blank line before this
proberge
2017/06/21 21:33:38
Done.
| |
| 35 | 37 |
| 36 EventLogMessage::EventLogMessage(const char* file, | 38 EventLogMessage::EventLogMessage(const char* file, |
| 37 int line, | 39 int line, |
| 38 LogSeverity severity) | 40 LogSeverity severity) |
| 39 : log_message_(file, line, severity) { | 41 : log_message_(file, line, severity) { |
| 40 } | 42 } |
| 41 | 43 |
| 42 EventLogMessage::~EventLogMessage() { | 44 EventLogMessage::~EventLogMessage() { |
| 43 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
| 44 // If g_event_source_name is nullptr (which it is per default) SYSLOG will | 46 // If g_event_source_name is nullptr (which it is per default) SYSLOG will |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 68 case LOG_ERROR: | 70 case LOG_ERROR: |
| 69 case LOG_FATAL: | 71 case LOG_FATAL: |
| 70 // The price of getting the stack trace is not worth the hassle for | 72 // The price of getting the stack trace is not worth the hassle for |
| 71 // non-error conditions. | 73 // non-error conditions. |
| 72 base::debug::StackTrace trace; | 74 base::debug::StackTrace trace; |
| 73 message.append(trace.ToString()); | 75 message.append(trace.ToString()); |
| 74 log_type = EVENTLOG_ERROR_TYPE; | 76 log_type = EVENTLOG_ERROR_TYPE; |
| 75 break; | 77 break; |
| 76 } | 78 } |
| 77 LPCSTR strings[1] = {message.data()}; | 79 LPCSTR strings[1] = {message.data()}; |
| 78 if (!ReportEventA(event_log_handle, log_type, BROWSER_CATEGORY, | 80 if (!ReportEventA(event_log_handle, log_type, g_category, g_event_id, NULL, 1, |
|
grt (UTC plus 2)
2017/06/21 20:26:15
NULL -> nullptr throughout
proberge
2017/06/21 21:33:38
Done.
| |
| 79 MSG_LOG_MESSAGE, NULL, 1, 0, strings, NULL)) { | 81 0, strings, NULL)) { |
| 80 stream() << " !!NOT ADDED TO EVENTLOG!!"; | 82 stream() << " !!NOT ADDED TO EVENTLOG!!"; |
| 81 } | 83 } |
| 82 #elif defined(OS_LINUX) | 84 #elif defined(OS_LINUX) |
| 83 const char kEventSource[] = "chrome"; | 85 const char kEventSource[] = "chrome"; |
| 84 openlog(kEventSource, LOG_NOWAIT | LOG_PID, LOG_USER); | 86 openlog(kEventSource, LOG_NOWAIT | LOG_PID, LOG_USER); |
| 85 // We can't use the defined names for the logging severity from syslog.h | 87 // We can't use the defined names for the logging severity from syslog.h |
| 86 // because they collide with the names of our own severity levels. Therefore | 88 // because they collide with the names of our own severity levels. Therefore |
| 87 // we use the actual values which of course do not match ours. | 89 // we use the actual values which of course do not match ours. |
| 88 // See sys/syslog.h for reference. | 90 // See sys/syslog.h for reference. |
| 89 int priority = 3; | 91 int priority = 3; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 100 case LOG_FATAL: | 102 case LOG_FATAL: |
| 101 priority = 2; | 103 priority = 2; |
| 102 break; | 104 break; |
| 103 } | 105 } |
| 104 syslog(priority, "%s", log_message_.str().c_str()); | 106 syslog(priority, "%s", log_message_.str().c_str()); |
| 105 closelog(); | 107 closelog(); |
| 106 #endif // defined(OS_WIN) | 108 #endif // defined(OS_WIN) |
| 107 } | 109 } |
| 108 | 110 |
| 109 } // namespace logging | 111 } // namespace logging |
| OLD | NEW |