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" |
7 | 7 |
8 #if defined(OS_WIN) | 8 #if defined(OS_WIN) |
9 #include "base/win/eventlog_messages.h" | 9 #include "base/win/eventlog_messages.h" |
10 | 10 |
11 #include <windows.h> | 11 #include <windows.h> |
12 #elif defined(OS_LINUX) | 12 #elif defined(OS_LINUX) |
13 #include <syslog.h> | 13 #include <syslog.h> |
14 #endif | 14 #endif |
15 | 15 |
16 #include <cstring> | 16 #include <cstring> |
17 #include <ostream> | 17 #include <ostream> |
18 #include <string> | 18 #include <string> |
19 | 19 |
20 namespace logging { | 20 namespace logging { |
21 | 21 |
22 #if defined(OS_WIN) | |
23 | |
24 namespace { | |
25 std::string g_event_source_name; | |
grt (UTC plus 2)
2016/11/25 15:25:34
non-POD globals are banned (https://google.github.
pastarmovj
2016/11/28 12:23:03
Done.
| |
26 } | |
27 | |
28 void SetEventSourceName(const std::string& name) { | |
29 g_event_source_name = name; | |
30 } | |
31 #endif // defined(OS_WIN) | |
32 | |
22 EventLogMessage::EventLogMessage(const char* file, | 33 EventLogMessage::EventLogMessage(const char* file, |
23 int line, | 34 int line, |
24 LogSeverity severity) | 35 LogSeverity severity) |
25 : log_message_(file, line, severity) { | 36 : log_message_(file, line, severity) { |
26 } | 37 } |
27 | 38 |
28 EventLogMessage::~EventLogMessage() { | 39 EventLogMessage::~EventLogMessage() { |
29 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
30 const char kEventSource[] = "chrome"; | 41 // If g_event_source_name is empty (which it is per default) this call will |
31 HANDLE event_log_handle = RegisterEventSourceA(NULL, kEventSource); | 42 // fail and SYSLOG will degrade gracefully to regular LOG with an extra error |
43 // suffix. If you see this happening most probably you are using SYSLOG before | |
44 // you called SetEventSourceName. | |
45 HANDLE event_log_handle = | |
46 RegisterEventSourceA(NULL, g_event_source_name.c_str()); | |
32 if (event_log_handle == NULL) { | 47 if (event_log_handle == NULL) { |
33 stream() << " !!NOT ADDED TO EVENTLOG!!"; | 48 stream() << " !!NOT ADDED TO EVENTLOG!!"; |
34 return; | 49 return; |
35 } | 50 } |
36 | 51 |
37 std::string message(log_message_.str()); | 52 std::string message(log_message_.str()); |
38 WORD log_type = EVENTLOG_ERROR_TYPE; | 53 WORD log_type = EVENTLOG_ERROR_TYPE; |
39 switch (log_message_.severity()) { | 54 switch (log_message_.severity()) { |
40 case LOG_INFO: | 55 case LOG_INFO: |
41 log_type = EVENTLOG_INFORMATION_TYPE; | 56 log_type = EVENTLOG_INFORMATION_TYPE; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 case LOG_FATAL: | 94 case LOG_FATAL: |
80 priority = 2; | 95 priority = 2; |
81 break; | 96 break; |
82 } | 97 } |
83 syslog(priority, "%s", log_message_.str().c_str()); | 98 syslog(priority, "%s", log_message_.str().c_str()); |
84 closelog(); | 99 closelog(); |
85 #endif // defined(OS_WIN) | 100 #endif // defined(OS_WIN) |
86 } | 101 } |
87 | 102 |
88 } // namespace logging | 103 } // namespace logging |
OLD | NEW |