Flutter Engine
The Flutter Engine
logging.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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#ifndef ACCESSIBILITY_BASE_LOGGING_H_
6#define ACCESSIBILITY_BASE_LOGGING_H_
7
8#include <sstream>
9
10#include "macros.h"
11
12namespace base {
13
15 public:
16 void operator&(std::ostream&) {}
17};
18
20 public:
21 LogMessage(const char* file,
22 int line,
23 const char* condition,
24 bool killProcess);
26
27 std::ostream& stream() { return stream_; }
28
29 private:
30 std::ostringstream stream_;
31 const char* file_;
32 const int line_;
33 const bool killProcess_;
34
35 BASE_DISALLOW_COPY_AND_ASSIGN(LogMessage);
36};
37
38[[noreturn]] void KillProcess();
39
40} // namespace base
41
42#define BASE_LOG_STREAM() \
43 ::base::LogMessage(__FILE__, __LINE__, nullptr, false).stream()
44
45#define BASE_LAZY_STREAM(stream, condition) \
46 !(condition) ? (void)0 : ::base::LogMessageVoidify() & (stream)
47
48#define BASE_EAT_STREAM_PARAMETERS(ignored) \
49 true || (ignored) \
50 ? (void)0 \
51 : ::base::LogMessageVoidify() & \
52 ::base::LogMessage(0, 0, nullptr, !(ignored)).stream()
53
54#define BASE_LOG() BASE_LAZY_STREAM(BASE_LOG_STREAM(), true)
55
56#define BASE_CHECK(condition) \
57 BASE_LAZY_STREAM( \
58 ::base::LogMessage(__FILE__, __LINE__, #condition, true).stream(), \
59 !(condition))
60
61#ifndef NDEBUG
62#define BASE_DLOG() BASE_LOG()
63#define BASE_DCHECK(condition) BASE_CHECK(condition)
64#else
65#define BASE_DLOG() BASE_EAT_STREAM_PARAMETERS(true)
66#define BASE_DCHECK(condition) BASE_EAT_STREAM_PARAMETERS(condition)
67#endif
68
69#define BASE_UNREACHABLE() \
70 { \
71 BASE_LOG() << "Reached unreachable code."; \
72 ::base::KillProcess(); \
73 }
74
75#endif // ACCESSIBILITY_BASE_LOGGING_H_
void operator&(std::ostream &)
Definition: logging.h:16
std::ostream & stream()
Definition: logging.h:27
LogMessage(const char *file, int line, const char *condition, bool killProcess)
Definition: logging.cc:33
void KillProcess()
Definition: logging.cc:61