logging_win.h revision c7f5f8508d98d5952d42ed7648c2a8f30a4da156
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 3// found in the LICENSE file. 4 5#ifndef BASE_LOGGING_WIN_H_ 6#define BASE_LOGGING_WIN_H_ 7 8#include <string> 9#include "base/basictypes.h" 10#include "base/event_trace_provider_win.h" 11#include "base/logging.h" 12 13namespace logging { 14 15// Event ID for the log messages we generate. 16extern const GUID kLogEventId; 17 18// Feature enable mask for LogEventProvider. 19enum LogEnableMask { 20 // If this bit is set in our provider enable mask, we will include 21 // a stack trace with every log message. 22 ENABLE_STACK_TRACE_CAPTURE = 0x0001, 23}; 24 25// The message types our log event provider generates. 26// ETW likes user message types to start at 10. 27enum LogMessageTypes { 28 // A textual only log message, contains a zero-terminated string. 29 LOG_MESSAGE = 10, 30 // A message with a stack trace, followed by the zero-terminated 31 // message text. 32 LOG_MESSAGE_WITH_STACKTRACE = 11, 33}; 34 35// Trace provider class to drive log control and transport 36// with Event Tracing for Windows. 37class LogEventProvider : public EtwTraceProvider { 38 public: 39 LogEventProvider(); 40 41 static bool LogMessage(int severity, const std::string& message); 42 static void Initialize(const GUID& provider_name); 43 static void Uninitialize(); 44 45 protected: 46 // Overridden to manipulate the log level on ETW control callbacks. 47 virtual void OnEventsEnabled(); 48 virtual void OnEventsDisabled(); 49 50 private: 51 // The log severity prior to OnEventsEnabled, 52 // restored in OnEventsDisabled. 53 logging::LogSeverity old_log_level_; 54 55 DISALLOW_COPY_AND_ASSIGN(LogEventProvider); 56}; 57 58} // namespace logging 59 60#endif // BASE_LOGGING_WIN_H_ 61