blob: 695c7f24b55da65fc9242b3e94a179dc11ccac58 [file] [log] [blame]
[email protected]2b07b8412009-11-25 15:26:341// 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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]2b07b8412009-11-25 15:26:348
9#include <string>
10#include "base/basictypes.h"
[email protected]ba50d1922010-11-06 15:39:4011#include "base/win/event_trace_provider.h"
[email protected]2b07b8412009-11-25 15:26:3412#include "base/logging.h"
13
14namespace logging {
15
16// Event ID for the log messages we generate.
17extern const GUID kLogEventId;
18
19// Feature enable mask for LogEventProvider.
20enum LogEnableMask {
21 // If this bit is set in our provider enable mask, we will include
22 // a stack trace with every log message.
23 ENABLE_STACK_TRACE_CAPTURE = 0x0001,
[email protected]162ac0f2010-11-04 15:50:4924 // 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,
[email protected]2b07b8412009-11-25 15:26:3428};
29
30// The message types our log event provider generates.
31// ETW likes user message types to start at 10.
32enum LogMessageTypes {
33 // A textual only log message, contains a zero-terminated string.
34 LOG_MESSAGE = 10,
35 // A message with a stack trace, followed by the zero-terminated
36 // message text.
37 LOG_MESSAGE_WITH_STACKTRACE = 11,
[email protected]162ac0f2010-11-04 15:50:4938 // 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,
[email protected]2b07b8412009-11-25 15:26:3444};
45
46// Trace provider class to drive log control and transport
47// with Event Tracing for Windows.
[email protected]ba50d1922010-11-06 15:39:4048class LogEventProvider : public base::win::EtwTraceProvider {
[email protected]2b07b8412009-11-25 15:26:3449 public:
50 LogEventProvider();
51
[email protected]162ac0f2010-11-04 15:50:4952 static bool LogMessage(logging::LogSeverity severity, const char* file,
53 int line, size_t message_start, const std::string& str);
54
[email protected]2b07b8412009-11-25 15:26:3455 static void Initialize(const GUID& provider_name);
56 static void Uninitialize();
57
58 protected:
59 // Overridden to manipulate the log level on ETW control callbacks.
60 virtual void OnEventsEnabled();
61 virtual void OnEventsDisabled();
62
63 private:
64 // The log severity prior to OnEventsEnabled,
65 // restored in OnEventsDisabled.
66 logging::LogSeverity old_log_level_;
67
68 DISALLOW_COPY_AND_ASSIGN(LogEventProvider);
69};
70
71} // namespace logging
72
73#endif // BASE_LOGGING_WIN_H_