1 #ifndef BENCHMARK_LOG_H_
2 #define BENCHMARK_LOG_H_
7 // NOTE: this is also defined in benchmark.h but we're trying to avoid a
9 // The _MSVC_LANG check should detect Visual Studio 2015 Update 3 and newer.
10 #if __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
11 #define BENCHMARK_HAS_CXX11
17 typedef std::basic_ostream
<char>&(EndLType
)(std::basic_ostream
<char>&);
20 friend LogType
& GetNullLogInstance();
21 friend LogType
& GetErrorLogInstance();
23 // FIXME: Add locking to output.
25 friend LogType
& operator<<(LogType
&, Tp
const&);
26 friend LogType
& operator<<(LogType
&, EndLType
*);
29 LogType(std::ostream
* out
) : out_(out
) {}
32 // NOTE: we could use BENCHMARK_DISALLOW_COPY_AND_ASSIGN but we shouldn't have
33 // a dependency on benchmark.h from here.
34 #ifndef BENCHMARK_HAS_CXX11
35 LogType(const LogType
&);
36 LogType
& operator=(const LogType
&);
38 LogType(const LogType
&) = delete;
39 LogType
& operator=(const LogType
&) = delete;
44 LogType
& operator<<(LogType
& log
, Tp
const& value
) {
51 inline LogType
& operator<<(LogType
& log
, EndLType
* m
) {
58 inline int& LogLevel() {
59 static int log_level
= 0;
63 inline LogType
& GetNullLogInstance() {
64 static LogType
null_log(static_cast<std::ostream
*>(nullptr));
68 inline LogType
& GetErrorLogInstance() {
69 static LogType
error_log(&std::clog
);
73 inline LogType
& GetLogInstanceForLevel(int level
) {
74 if (level
<= LogLevel()) {
75 return GetErrorLogInstance();
77 return GetNullLogInstance();
80 } // end namespace internal
81 } // end namespace benchmark
85 (::benchmark::internal::GetLogInstanceForLevel(x) << "-- LOG(" << x << "):" \