blob: 38508a32466f512324c200cca88f47aa18bd773a [file] [log] [blame]
[email protected]9bcc1b012012-03-12 21:42:111// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]2b07b8412009-11-25 15:26:342// 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]2b07b8412009-11-25 15:26:347
8#include <string>
[email protected]9493ee95c2011-03-28 23:48:449
[email protected]0bea7252011-08-05 15:34:0010#include "base/base_export.h"
[email protected]2b07b8412009-11-25 15:26:3411#include "base/basictypes.h"
[email protected]ba50d1922010-11-06 15:39:4012#include "base/win/event_trace_provider.h"
[email protected]2b07b8412009-11-25 15:26:3413#include "base/logging.h"
14
[email protected]864b5582010-12-04 23:00:1015template <typename Type>
16struct StaticMemorySingletonTraits;
17
[email protected]2b07b8412009-11-25 15:26:3418namespace logging {
19
20// Event ID for the log messages we generate.
[email protected]fb471342013-07-01 17:11:3621EXTERN_C BASE_EXPORT const GUID kLogEventId;
[email protected]2b07b8412009-11-25 15:26:3422
23// Feature enable mask for LogEventProvider.
24enum LogEnableMask {
25 // If this bit is set in our provider enable mask, we will include
26 // a stack trace with every log message.
27 ENABLE_STACK_TRACE_CAPTURE = 0x0001,
[email protected]162ac0f2010-11-04 15:50:4928 // If this bit is set in our provider enable mask, the provider will log
29 // a LOG message with only the textual content of the message, and no
30 // stack trace.
31 ENABLE_LOG_MESSAGE_ONLY = 0x0002,
[email protected]2b07b8412009-11-25 15:26:3432};
33
34// The message types our log event provider generates.
35// ETW likes user message types to start at 10.
36enum LogMessageTypes {
37 // A textual only log message, contains a zero-terminated string.
38 LOG_MESSAGE = 10,
39 // A message with a stack trace, followed by the zero-terminated
40 // message text.
41 LOG_MESSAGE_WITH_STACKTRACE = 11,
[email protected]162ac0f2010-11-04 15:50:4942 // A message with:
43 // a stack trace,
44 // the line number as a four byte integer,
45 // the file as a zero terminated UTF8 string,
46 // the zero-terminated UTF8 message text.
47 LOG_MESSAGE_FULL = 12,
[email protected]2b07b8412009-11-25 15:26:3448};
49
50// Trace provider class to drive log control and transport
51// with Event Tracing for Windows.
[email protected]0bea7252011-08-05 15:34:0052class BASE_EXPORT LogEventProvider : public base::win::EtwTraceProvider {
[email protected]2b07b8412009-11-25 15:26:3453 public:
[email protected]864b5582010-12-04 23:00:1054 static LogEventProvider* GetInstance();
[email protected]2b07b8412009-11-25 15:26:3455
[email protected]162ac0f2010-11-04 15:50:4956 static bool LogMessage(logging::LogSeverity severity, const char* file,
57 int line, size_t message_start, const std::string& str);
58
[email protected]2b07b8412009-11-25 15:26:3459 static void Initialize(const GUID& provider_name);
60 static void Uninitialize();
61
62 protected:
63 // Overridden to manipulate the log level on ETW control callbacks.
64 virtual void OnEventsEnabled();
65 virtual void OnEventsDisabled();
66
67 private:
[email protected]864b5582010-12-04 23:00:1068 LogEventProvider();
69
[email protected]2b07b8412009-11-25 15:26:3470 // The log severity prior to OnEventsEnabled,
71 // restored in OnEventsDisabled.
72 logging::LogSeverity old_log_level_;
73
[email protected]864b5582010-12-04 23:00:1074 friend struct StaticMemorySingletonTraits<LogEventProvider>;
[email protected]2b07b8412009-11-25 15:26:3475 DISALLOW_COPY_AND_ASSIGN(LogEventProvider);
76};
77
78} // namespace logging
79
80#endif // BASE_LOGGING_WIN_H_