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 CHROME_TEST_LOGGING_WIN_FILE_LOGGER_H_
6 #define CHROME_TEST_LOGGING_WIN_FILE_LOGGER_H_
10 #include "base/basictypes.h"
11 #include "base/strings/string16.h"
12 #include "base/win/event_trace_controller.h"
18 namespace logging_win
{
20 // A file logger instance captures LOG messages and trace events emitted via
21 // Event Tracing for Windows (ETW) and sends them to a file. Events can be
22 // pulled from the file sometime later with PrintLogFile or ReadLogFile
23 // (currently in log_file_printer_win.h and log_file_reader_win.h,
26 // Important usage notes (read this):
27 // - Due to the nature of event generation, only one instance of this class may
28 // be initialized at a time.
29 // - This class is not thread safe.
30 // - This class uses facilities that require the process to run with admin
31 // rights; StartLogging() will return false if this is not the case.
34 enum EventProviderBits
{
35 // Log messages from chrome.exe.
36 CHROME_LOG_PROVIDER
= 1 << 0,
37 // Log messages from npchrome_frame.dll.
38 CHROME_FRAME_LOG_PROVIDER
= 1 << 1,
39 // Log messages from the current process.
40 CHROME_TESTS_LOG_PROVIDER
= 1 << 2,
42 CHROME_TRACE_EVENT_PROVIDER
= 1 << 3,
45 static const uint32 kAllEventProviders
= (CHROME_LOG_PROVIDER
|
46 CHROME_FRAME_LOG_PROVIDER
|
47 CHROME_TESTS_LOG_PROVIDER
|
48 CHROME_TRACE_EVENT_PROVIDER
);
53 // Initializes the instance to collect logs from all supported providers.
56 // Initializes the instance to collect logs from the providers present in
57 // the given mask; see EventProviderBits.
58 void Initialize(uint32 event_provider_mask
);
60 // Starts capturing logs from all providers into |log_file|. The common file
61 // extension for such files is .etl. Returns false if the session could not
62 // be started (e.g., if not running as admin) or if no providers could be
64 bool StartLogging(const base::FilePath
& log_file
);
66 // Stops capturing logs.
69 // Returns true if logs are being captured.
70 bool is_logging() const {
71 return controller_
.session_name() && *controller_
.session_name();
75 bool EnableProviders();
76 void DisableProviders();
78 static bool is_initialized_
;
80 base::win::EtwTraceController controller_
;
81 uint32 event_provider_mask_
;
83 DISALLOW_COPY_AND_ASSIGN(FileLogger
);
86 } // namespace logging_win
88 #endif // CHROME_TEST_LOGGING_WIN_FILE_LOGGER_H_