forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.h
98 lines (73 loc) · 2.88 KB
/
logging.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_FML_LOGGING_H_
#define FLUTTER_FML_LOGGING_H_
#include <sstream>
#include "flutter/fml/log_level.h"
#include "flutter/fml/macros.h"
namespace fml {
class LogMessageVoidify {
public:
void operator&(std::ostream&) {}
};
class LogMessage {
public:
LogMessage(LogSeverity severity,
const char* file,
int line,
const char* condition);
~LogMessage();
std::ostream& stream() { return stream_; }
private:
std::ostringstream stream_;
const LogSeverity severity_;
const char* file_;
const int line_;
FML_DISALLOW_COPY_AND_ASSIGN(LogMessage);
};
// Gets the FML_VLOG default verbosity level.
int GetVlogVerbosity();
// Returns true if |severity| is at or above the current minimum log level.
// LOG_FATAL and above is always true.
bool ShouldCreateLogMessage(LogSeverity severity);
[[noreturn]] void KillProcess();
} // namespace fml
#define FML_LOG_STREAM(severity) \
::fml::LogMessage(::fml::LOG_##severity, __FILE__, __LINE__, nullptr).stream()
#define FML_LAZY_STREAM(stream, condition) \
!(condition) ? (void)0 : ::fml::LogMessageVoidify() & (stream)
#define FML_EAT_STREAM_PARAMETERS(ignored) \
true || (ignored) \
? (void)0 \
: ::fml::LogMessageVoidify() & \
::fml::LogMessage(::fml::LOG_FATAL, 0, 0, nullptr).stream()
#define FML_LOG_IS_ON(severity) \
(::fml::ShouldCreateLogMessage(::fml::LOG_##severity))
#define FML_LOG(severity) \
FML_LAZY_STREAM(FML_LOG_STREAM(severity), FML_LOG_IS_ON(severity))
#define FML_CHECK(condition) \
FML_LAZY_STREAM( \
::fml::LogMessage(::fml::LOG_FATAL, __FILE__, __LINE__, #condition) \
.stream(), \
!(condition))
#define FML_VLOG_IS_ON(verbose_level) \
((verbose_level) <= ::fml::GetVlogVerbosity())
// The VLOG macros log with negative verbosities.
#define FML_VLOG_STREAM(verbose_level) \
::fml::LogMessage(-verbose_level, __FILE__, __LINE__, nullptr).stream()
#define FML_VLOG(verbose_level) \
FML_LAZY_STREAM(FML_VLOG_STREAM(verbose_level), FML_VLOG_IS_ON(verbose_level))
#ifndef NDEBUG
#define FML_DLOG(severity) FML_LOG(severity)
#define FML_DCHECK(condition) FML_CHECK(condition)
#else
#define FML_DLOG(severity) FML_EAT_STREAM_PARAMETERS(true)
#define FML_DCHECK(condition) FML_EAT_STREAM_PARAMETERS(condition)
#endif
#define FML_UNREACHABLE() \
{ \
FML_LOG(ERROR) << "Reached unreachable code."; \
::fml::KillProcess(); \
}
#endif // FLUTTER_FML_LOGGING_H_