michael@0: // Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_LOGGING_WIN_H_ michael@0: #define BASE_LOGGING_WIN_H_ michael@0: michael@0: #include michael@0: michael@0: #include "base/base_export.h" michael@0: #include "base/basictypes.h" michael@0: #include "base/win/event_trace_provider.h" michael@0: #include "base/logging.h" michael@0: michael@0: template michael@0: struct StaticMemorySingletonTraits; michael@0: michael@0: namespace logging { michael@0: michael@0: // Event ID for the log messages we generate. michael@0: EXTERN_C BASE_EXPORT const GUID kLogEventId; michael@0: michael@0: // Feature enable mask for LogEventProvider. michael@0: enum LogEnableMask { michael@0: // If this bit is set in our provider enable mask, we will include michael@0: // a stack trace with every log message. michael@0: ENABLE_STACK_TRACE_CAPTURE = 0x0001, michael@0: // If this bit is set in our provider enable mask, the provider will log michael@0: // a LOG message with only the textual content of the message, and no michael@0: // stack trace. michael@0: ENABLE_LOG_MESSAGE_ONLY = 0x0002, michael@0: }; michael@0: michael@0: // The message types our log event provider generates. michael@0: // ETW likes user message types to start at 10. michael@0: enum LogMessageTypes { michael@0: // A textual only log message, contains a zero-terminated string. michael@0: LOG_MESSAGE = 10, michael@0: // A message with a stack trace, followed by the zero-terminated michael@0: // message text. michael@0: LOG_MESSAGE_WITH_STACKTRACE = 11, michael@0: // A message with: michael@0: // a stack trace, michael@0: // the line number as a four byte integer, michael@0: // the file as a zero terminated UTF8 string, michael@0: // the zero-terminated UTF8 message text. michael@0: LOG_MESSAGE_FULL = 12, michael@0: }; michael@0: michael@0: // Trace provider class to drive log control and transport michael@0: // with Event Tracing for Windows. michael@0: class BASE_EXPORT LogEventProvider : public base::win::EtwTraceProvider { michael@0: public: michael@0: static LogEventProvider* GetInstance(); michael@0: michael@0: static bool LogMessage(logging::LogSeverity severity, const char* file, michael@0: int line, size_t message_start, const std::string& str); michael@0: michael@0: static void Initialize(const GUID& provider_name); michael@0: static void Uninitialize(); michael@0: michael@0: protected: michael@0: // Overridden to manipulate the log level on ETW control callbacks. michael@0: virtual void OnEventsEnabled(); michael@0: virtual void OnEventsDisabled(); michael@0: michael@0: private: michael@0: LogEventProvider(); michael@0: michael@0: // The log severity prior to OnEventsEnabled, michael@0: // restored in OnEventsDisabled. michael@0: logging::LogSeverity old_log_level_; michael@0: michael@0: friend struct StaticMemorySingletonTraits; michael@0: DISALLOW_COPY_AND_ASSIGN(LogEventProvider); michael@0: }; michael@0: michael@0: } // namespace logging michael@0: michael@0: #endif // BASE_LOGGING_WIN_H_