[email protected] | 9bcc1b01 | 2012-03-12 21:42:11 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_LOGGING_WIN_H_ |
| 6 | #define BASE_LOGGING_WIN_H_ |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 7 | |
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 10 | #include <string> |
[email protected] | 9493ee95c | 2011-03-28 23:48:44 | [diff] [blame] | 11 | |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 12 | #include "base/base_export.h" |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 13 | #include "base/logging.h" |
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame] | 14 | #include "base/macros.h" |
| 15 | #include "base/win/event_trace_provider.h" |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 16 | |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 17 | namespace base { |
[email protected] | 864b558 | 2010-12-04 23:00:10 | [diff] [blame] | 18 | template <typename Type> |
| 19 | struct StaticMemorySingletonTraits; |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 20 | } // namespace base |
[email protected] | 864b558 | 2010-12-04 23:00:10 | [diff] [blame] | 21 | |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 22 | namespace logging { |
| 23 | |
| 24 | // Event ID for the log messages we generate. |
[email protected] | fb47134 | 2013-07-01 17:11:36 | [diff] [blame] | 25 | EXTERN_C BASE_EXPORT const GUID kLogEventId; |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 26 | |
| 27 | // Feature enable mask for LogEventProvider. |
| 28 | enum LogEnableMask { |
| 29 | // If this bit is set in our provider enable mask, we will include |
| 30 | // a stack trace with every log message. |
| 31 | ENABLE_STACK_TRACE_CAPTURE = 0x0001, |
[email protected] | 162ac0f | 2010-11-04 15:50:49 | [diff] [blame] | 32 | // If this bit is set in our provider enable mask, the provider will log |
| 33 | // a LOG message with only the textual content of the message, and no |
| 34 | // stack trace. |
| 35 | ENABLE_LOG_MESSAGE_ONLY = 0x0002, |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | // The message types our log event provider generates. |
| 39 | // ETW likes user message types to start at 10. |
| 40 | enum LogMessageTypes { |
| 41 | // A textual only log message, contains a zero-terminated string. |
| 42 | LOG_MESSAGE = 10, |
| 43 | // A message with a stack trace, followed by the zero-terminated |
| 44 | // message text. |
| 45 | LOG_MESSAGE_WITH_STACKTRACE = 11, |
[email protected] | 162ac0f | 2010-11-04 15:50:49 | [diff] [blame] | 46 | // A message with: |
| 47 | // a stack trace, |
| 48 | // the line number as a four byte integer, |
| 49 | // the file as a zero terminated UTF8 string, |
| 50 | // the zero-terminated UTF8 message text. |
| 51 | LOG_MESSAGE_FULL = 12, |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | // Trace provider class to drive log control and transport |
| 55 | // with Event Tracing for Windows. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 56 | class BASE_EXPORT LogEventProvider : public base::win::EtwTraceProvider { |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 57 | public: |
[email protected] | 864b558 | 2010-12-04 23:00:10 | [diff] [blame] | 58 | static LogEventProvider* GetInstance(); |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 59 | |
[email protected] | 162ac0f | 2010-11-04 15:50:49 | [diff] [blame] | 60 | static bool LogMessage(logging::LogSeverity severity, const char* file, |
| 61 | int line, size_t message_start, const std::string& str); |
| 62 | |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 63 | static void Initialize(const GUID& provider_name); |
| 64 | static void Uninitialize(); |
| 65 | |
| 66 | protected: |
| 67 | // Overridden to manipulate the log level on ETW control callbacks. |
dcheng | fbce126 | 2015-04-17 07:35:46 | [diff] [blame] | 68 | void OnEventsEnabled() override; |
| 69 | void OnEventsDisabled() override; |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 70 | |
| 71 | private: |
[email protected] | 864b558 | 2010-12-04 23:00:10 | [diff] [blame] | 72 | LogEventProvider(); |
| 73 | |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 74 | // The log severity prior to OnEventsEnabled, |
| 75 | // restored in OnEventsDisabled. |
| 76 | logging::LogSeverity old_log_level_; |
| 77 | |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 78 | friend struct base::StaticMemorySingletonTraits<LogEventProvider>; |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 79 | DISALLOW_COPY_AND_ASSIGN(LogEventProvider); |
| 80 | }; |
| 81 | |
| 82 | } // namespace logging |
| 83 | |
| 84 | #endif // BASE_LOGGING_WIN_H_ |