| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef BASE_LOGGING_WIN_H_ | 5 #ifndef BASE_LOGGING_WIN_H_ |
| 6 #define BASE_LOGGING_WIN_H_ | 6 #define BASE_LOGGING_WIN_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/event_trace_provider_win.h" | 11 #include "base/event_trace_provider_win.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 | 13 |
| 14 namespace logging { | 14 namespace logging { |
| 15 | 15 |
| 16 // Event ID for the log messages we generate. | 16 // Event ID for the log messages we generate. |
| 17 extern const GUID kLogEventId; | 17 extern const GUID kLogEventId; |
| 18 | 18 |
| 19 // Feature enable mask for LogEventProvider. | 19 // Feature enable mask for LogEventProvider. |
| 20 enum LogEnableMask { | 20 enum LogEnableMask { |
| 21 // If this bit is set in our provider enable mask, we will include | 21 // If this bit is set in our provider enable mask, we will include |
| 22 // a stack trace with every log message. | 22 // a stack trace with every log message. |
| 23 ENABLE_STACK_TRACE_CAPTURE = 0x0001, | 23 ENABLE_STACK_TRACE_CAPTURE = 0x0001, |
| 24 // If this bit is set in our provider enable mask, the provider will log |
| 25 // a LOG message with only the textual content of the message, and no |
| 26 // stack trace. |
| 27 ENABLE_LOG_MESSAGE_ONLY = 0x0002, |
| 24 }; | 28 }; |
| 25 | 29 |
| 26 // The message types our log event provider generates. | 30 // The message types our log event provider generates. |
| 27 // ETW likes user message types to start at 10. | 31 // ETW likes user message types to start at 10. |
| 28 enum LogMessageTypes { | 32 enum LogMessageTypes { |
| 29 // A textual only log message, contains a zero-terminated string. | 33 // A textual only log message, contains a zero-terminated string. |
| 30 LOG_MESSAGE = 10, | 34 LOG_MESSAGE = 10, |
| 31 // A message with a stack trace, followed by the zero-terminated | 35 // A message with a stack trace, followed by the zero-terminated |
| 32 // message text. | 36 // message text. |
| 33 LOG_MESSAGE_WITH_STACKTRACE = 11, | 37 LOG_MESSAGE_WITH_STACKTRACE = 11, |
| 38 // A message with: |
| 39 // a stack trace, |
| 40 // the line number as a four byte integer, |
| 41 // the file as a zero terminated UTF8 string, |
| 42 // the zero-terminated UTF8 message text. |
| 43 LOG_MESSAGE_FULL = 12, |
| 34 }; | 44 }; |
| 35 | 45 |
| 36 // Trace provider class to drive log control and transport | 46 // Trace provider class to drive log control and transport |
| 37 // with Event Tracing for Windows. | 47 // with Event Tracing for Windows. |
| 38 class LogEventProvider : public EtwTraceProvider { | 48 class LogEventProvider : public EtwTraceProvider { |
| 39 public: | 49 public: |
| 40 LogEventProvider(); | 50 LogEventProvider(); |
| 41 | 51 |
| 42 static bool LogMessage(int severity, const std::string& message); | 52 static bool LogMessage(logging::LogSeverity severity, const char* file, |
| 53 int line, size_t message_start, const std::string& str); |
| 54 |
| 43 static void Initialize(const GUID& provider_name); | 55 static void Initialize(const GUID& provider_name); |
| 44 static void Uninitialize(); | 56 static void Uninitialize(); |
| 45 | 57 |
| 46 protected: | 58 protected: |
| 47 // Overridden to manipulate the log level on ETW control callbacks. | 59 // Overridden to manipulate the log level on ETW control callbacks. |
| 48 virtual void OnEventsEnabled(); | 60 virtual void OnEventsEnabled(); |
| 49 virtual void OnEventsDisabled(); | 61 virtual void OnEventsDisabled(); |
| 50 | 62 |
| 51 private: | 63 private: |
| 52 // The log severity prior to OnEventsEnabled, | 64 // The log severity prior to OnEventsEnabled, |
| 53 // restored in OnEventsDisabled. | 65 // restored in OnEventsDisabled. |
| 54 logging::LogSeverity old_log_level_; | 66 logging::LogSeverity old_log_level_; |
| 55 | 67 |
| 56 DISALLOW_COPY_AND_ASSIGN(LogEventProvider); | 68 DISALLOW_COPY_AND_ASSIGN(LogEventProvider); |
| 57 }; | 69 }; |
| 58 | 70 |
| 59 } // namespace logging | 71 } // namespace logging |
| 60 | 72 |
| 61 #endif // BASE_LOGGING_WIN_H_ | 73 #endif // BASE_LOGGING_WIN_H_ |
| OLD | NEW |