Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: tools/relocation_packer/src/debug.cc

Issue 670183003: Update from chromium 62675d9fb31fb8cedc40f68e78e8445a74f362e7 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/relocation_packer/src/debug.h ('k') | tools/relocation_packer/src/debug_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "debug.h"
6
7 #include <stdlib.h>
8 #include <iostream>
9 #include <string>
10
11 namespace relocation_packer {
12
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;
19 }
20
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;
32 }
33 stream_.flush();
34 *log << tag << ": " << stream_.str() << std::endl;
35 }
36 if (severity_ == FATAL)
37 abort();
38 }
39 }
40
41 // Reset to initial state.
42 void Logger::Reset() {
43 max_level_ = -1;
44 info_stream_ = &std::cout;
45 error_stream_ = &std::cerr;
46 }
47
48 // Verbosity. Not thread-safe.
49 int Logger::max_level_ = -1;
50
51 // Logging streams. Not thread-safe.
52 std::ostream* Logger::info_stream_ = &std::cout;
53 std::ostream* Logger::error_stream_ = &std::cerr;
54
55 } // namespace relocation_packer
OLDNEW
« no previous file with comments | « tools/relocation_packer/src/debug.h ('k') | tools/relocation_packer/src/debug_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698