Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / base / logging_win.h
blobde34a644093dc45f7bd67e68523bb86d527b0d31
1 // Copyright (c) 2012 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.
5 #ifndef BASE_LOGGING_WIN_H_
6 #define BASE_LOGGING_WIN_H_
8 #include <string>
10 #include "base/base_export.h"
11 #include "base/basictypes.h"
12 #include "base/win/event_trace_provider.h"
13 #include "base/logging.h"
15 namespace base {
16 template <typename Type>
17 struct StaticMemorySingletonTraits;
18 } // namespace base
20 namespace logging {
22 // Event ID for the log messages we generate.
23 EXTERN_C BASE_EXPORT const GUID kLogEventId;
25 // Feature enable mask for LogEventProvider.
26 enum LogEnableMask {
27 // If this bit is set in our provider enable mask, we will include
28 // a stack trace with every log message.
29 ENABLE_STACK_TRACE_CAPTURE = 0x0001,
30 // If this bit is set in our provider enable mask, the provider will log
31 // a LOG message with only the textual content of the message, and no
32 // stack trace.
33 ENABLE_LOG_MESSAGE_ONLY = 0x0002,
36 // The message types our log event provider generates.
37 // ETW likes user message types to start at 10.
38 enum LogMessageTypes {
39 // A textual only log message, contains a zero-terminated string.
40 LOG_MESSAGE = 10,
41 // A message with a stack trace, followed by the zero-terminated
42 // message text.
43 LOG_MESSAGE_WITH_STACKTRACE = 11,
44 // A message with:
45 // a stack trace,
46 // the line number as a four byte integer,
47 // the file as a zero terminated UTF8 string,
48 // the zero-terminated UTF8 message text.
49 LOG_MESSAGE_FULL = 12,
52 // Trace provider class to drive log control and transport
53 // with Event Tracing for Windows.
54 class BASE_EXPORT LogEventProvider : public base::win::EtwTraceProvider {
55 public:
56 static LogEventProvider* GetInstance();
58 static bool LogMessage(logging::LogSeverity severity, const char* file,
59 int line, size_t message_start, const std::string& str);
61 static void Initialize(const GUID& provider_name);
62 static void Uninitialize();
64 protected:
65 // Overridden to manipulate the log level on ETW control callbacks.
66 void OnEventsEnabled() override;
67 void OnEventsDisabled() override;
69 private:
70 LogEventProvider();
72 // The log severity prior to OnEventsEnabled,
73 // restored in OnEventsDisabled.
74 logging::LogSeverity old_log_level_;
76 friend struct base::StaticMemorySingletonTraits<LogEventProvider>;
77 DISALLOW_COPY_AND_ASSIGN(LogEventProvider);
80 } // namespace logging
82 #endif // BASE_LOGGING_WIN_H_