1 // Copyright 2015 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 COMPONENTS_PROXIMITY_AUTH_LOGGING_LOGGING_H
6 #define COMPONENTS_PROXIMITY_AUTH_LOGGING_LOGGING_H
10 #include "base/logging.h"
12 namespace proximity_auth
{
14 // Use the PA_LOG() macro for all logging related to Proximity Auth, so the
15 // system is aware of all logs related to this feature. We display these logs in
16 // the debug WebUI (chrome://proximity-auth).
18 // PA_LOG() has the same interface as the standard LOG() macro and also creates
19 // a normal log message of the same severity.
21 // PA_LOG(INFO) << "Waiting for " << x << " pending requests.";
22 // PA_LOG(ERROR) << "Request failed: " << error_string;
23 #define PA_LOG(severity) \
24 proximity_auth::ScopedLogMessage(__FILE__, __LINE__, \
25 logging::LOG_##severity).stream()
27 // Disables all logging while in scope. Intended to be called only from test
28 // code, to clean up test output.
29 class ScopedDisableLoggingForTesting
{
31 ScopedDisableLoggingForTesting();
32 ~ScopedDisableLoggingForTesting();
35 // An intermediate object used by the PA_LOG macro, wrapping a
36 // logging::LogMessage instance. When this object is destroyed, the message will
37 // be logged with the standard logging system and also added to Proximity Auth
38 // specific log buffer. You should use the PA_LOG() macro instead of this class
40 class ScopedLogMessage
{
42 ScopedLogMessage(const char* file
, int line
, logging::LogSeverity severity
);
45 std::ostream
& stream() { return stream_
; }
50 logging::LogSeverity severity_
;
51 std::ostringstream stream_
;
53 DISALLOW_COPY_AND_ASSIGN(ScopedLogMessage
);
56 } // namespace proximity_auth
58 #endif // COMPONENTS_PROXIMITY_AUTH_LOGGING_LOGGING_H