summaryrefslogtreecommitdiffstats
path: root/components/proximity_auth/logging/logging.cc
blob: 4ab7920b9e64bfc11e370ad095ffafd713ff27a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/proximity_auth/logging/logging.h"

#include "components/proximity_auth/logging/log_buffer.h"

namespace proximity_auth {
namespace {

bool g_logging_enabled = true;

}  // namespace

ScopedDisableLoggingForTesting::ScopedDisableLoggingForTesting() {
  g_logging_enabled = false;
}

ScopedDisableLoggingForTesting::~ScopedDisableLoggingForTesting() {
  g_logging_enabled = true;
}

ScopedLogMessage::ScopedLogMessage(const char* file,
                                   int line,
                                   logging::LogSeverity severity)
    : file_(file), line_(line), severity_(severity) {
}

ScopedLogMessage::~ScopedLogMessage() {
  if (!g_logging_enabled)
    return;

  LogBuffer::GetInstance()->AddLogMessage(LogBuffer::LogMessage(
      stream_.str(), base::Time::Now(), file_, line_, severity_));

  // The destructor of |log_message| also creates a log for the standard logging
  // system.
  logging::LogMessage log_message(file_, line_, severity_);
  log_message.stream() << stream_.str();
}

}  // proximity_auth