Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / android_platform / bionic / tools / relocation_packer / src / debug.cc
blob29d7ab067445412467424310076763f3e268a79b
1 // Copyright 2014 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 #include "debug.h"
7 #include <stdlib.h>
8 #include <iostream>
9 #include <string>
11 namespace relocation_packer {
13 // Construct a new message logger. Prints if level is less than or equal to
14 // the level set with SetVerbose() and predicate is true.
15 Logger::Logger(Severity severity, int level, bool predicate) {
16 severity_ = severity;
17 level_ = level;
18 predicate_ = predicate;
21 // On destruction, flush and print the strings accumulated. Abort if FATAL.
22 Logger::~Logger() {
23 if (predicate_) {
24 if (level_ <= max_level_) {
25 std::ostream* log = severity_ == INFO ? info_stream_ : error_stream_;
26 std::string tag;
27 switch (severity_) {
28 case INFO: tag = "INFO"; break;
29 case WARNING: tag = "WARNING"; break;
30 case ERROR: tag = "ERROR"; break;
31 case FATAL: tag = "FATAL"; break;
33 stream_.flush();
34 *log << tag << ": " << stream_.str() << std::endl;
36 if (severity_ == FATAL)
37 abort();
41 // Reset to initial state.
42 void Logger::Reset() {
43 max_level_ = -1;
44 info_stream_ = &std::cout;
45 error_stream_ = &std::cerr;
48 // Verbosity. Not thread-safe.
49 int Logger::max_level_ = -1;
51 // Logging streams. Not thread-safe.
52 std::ostream* Logger::info_stream_ = &std::cout;
53 std::ostream* Logger::error_stream_ = &std::cerr;
55 } // namespace relocation_packer