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.
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
) {
18 predicate_
= predicate
;
21 // On destruction, flush and print the strings accumulated. Abort if FATAL.
24 if (level_
<= max_level_
) {
25 std::ostream
* log
= severity_
== INFO
? info_stream_
: error_stream_
;
28 case INFO
: tag
= "INFO"; break;
29 case WARNING
: tag
= "WARNING"; break;
30 case ERROR
: tag
= "ERROR"; break;
31 case FATAL
: tag
= "FATAL"; break;
34 *log
<< tag
<< ": " << stream_
.str() << std::endl
;
36 if (severity_
== FATAL
)
41 // Reset to initial state.
42 void Logger::Reset() {
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