19#define __builtin_available(v1, v2) false
75#ifdef _LOG_TAG_INTERNAL
76#error "_LOG_TAG_INTERNAL must not be defined"
79#define _LOG_TAG_INTERNAL LOG_TAG
81#define _LOG_TAG_INTERNAL nullptr
123void StdioLogger(
LogId log_buffer_id,
LogSeverity severity,
const char* tag,
const char* file,
unsigned int line,
const char* message);
138 unsigned int line,
const char* message);
153#define INIT_LOGGING_DEFAULT_LOGGER LogdLogger()
155#define INIT_LOGGING_DEFAULT_LOGGER StderrLogger
160#undef INIT_LOGGING_DEFAULT_LOGGER
171#define SEVERITY_LAMBDA(severity) ([&]() { \
172 using ::android::base::VERBOSE; \
173 using ::android::base::DEBUG; \
174 using ::android::base::INFO; \
175 using ::android::base::WARNING; \
176 using ::android::base::ERROR; \
177 using ::android::base::FATAL_WITHOUT_ABORT; \
178 using ::android::base::FATAL; \
179 return (severity); }())
181#ifdef __clang_analyzer__
184#define ABORT_AFTER_LOG_FATAL for (;; abort())
186struct LogAbortAfterFullExpr {
187 ~LogAbortAfterFullExpr()
__attribute__((noreturn)) { abort(); }
188 explicit operator bool()
const {
return false; }
192#define ABORT_AFTER_LOG_EXPR_IF(c, x) (((c) && ::android::base::LogAbortAfterFullExpr()) || (x))
194#define MUST_LOG_MESSAGE(severity) (SEVERITY_LAMBDA(severity) == ::android::base::FATAL)
196#define ABORT_AFTER_LOG_FATAL
197#define ABORT_AFTER_LOG_EXPR_IF(c, x) (x)
198#define MUST_LOG_MESSAGE(severity) false
200#define ABORT_AFTER_LOG_FATAL_EXPR(x) ABORT_AFTER_LOG_EXPR_IF(true, x)
203#define WOULD_LOG(severity) \
204 (UNLIKELY(::android::base::ShouldLog(SEVERITY_LAMBDA(severity), _LOG_TAG_INTERNAL)) || \
205 MUST_LOG_MESSAGE(severity))
214#define LOG_STREAM(severity) \
215 ::android::base::LogMessage(__FILE__, __LINE__, SEVERITY_LAMBDA(severity), _LOG_TAG_INTERNAL, \
223#define LOG(severity) LOGGING_PREAMBLE(severity) && LOG_STREAM(severity)
228#define LOGGING_PREAMBLE(severity) \
229 (WOULD_LOG(severity) && \
230 ABORT_AFTER_LOG_EXPR_IF((SEVERITY_LAMBDA(severity)) == ::android::base::FATAL, true) && \
231 ::android::base::ErrnoRestorer())
235#define PLOG(severity) \
236 LOGGING_PREAMBLE(severity) && \
237 ::android::base::LogMessage(__FILE__, __LINE__, SEVERITY_LAMBDA(severity), \
238 _LOG_TAG_INTERNAL, errno) \
242#define UNIMPLEMENTED(level) \
243 LOG(level) << __PRETTY_FUNCTION__ << " unimplemented "
252 LIKELY((x)) || ABORT_AFTER_LOG_FATAL_EXPR(false) || \
253 ::android::base::LogMessage(__FILE__, __LINE__, ::android::base::FATAL, _LOG_TAG_INTERNAL, \
256 << "Check failed: " #x << " "
260#define CHECK_OP(LHS, RHS, OP) \
261 for (auto _values = ::android::base::MakeEagerEvaluator(LHS, RHS); \
262 UNLIKELY(!(_values.lhs.v OP _values.rhs.v)); \
264 ABORT_AFTER_LOG_FATAL \
265 ::android::base::LogMessage(__FILE__, __LINE__, ::android::base::FATAL, _LOG_TAG_INTERNAL, -1) \
267 << "Check failed: " << #LHS << " " << #OP << " " << #RHS << " (" #LHS "=" \
268 << ::android::base::LogNullGuard<decltype(_values.lhs.v)>::Guard(_values.lhs.v) \
270 << ::android::base::LogNullGuard<decltype(_values.rhs.v)>::Guard(_values.rhs.v) \
280#define CHECK_EQ(x, y) CHECK_OP(x, y, == )
281#define CHECK_NE(x, y) CHECK_OP(x, y, != )
282#define CHECK_LE(x, y) CHECK_OP(x, y, <= )
283#define CHECK_LT(x, y) CHECK_OP(x, y, < )
284#define CHECK_GE(x, y) CHECK_OP(x, y, >= )
285#define CHECK_GT(x, y) CHECK_OP(x, y, > )
289#define CHECK_STROP(s1, s2, sense) \
290 while (UNLIKELY((strcmp(s1, s2) == 0) != (sense))) \
291 ABORT_AFTER_LOG_FATAL \
292 ::android::base::LogMessage(__FILE__, __LINE__, ::android::base::FATAL, \
293 _LOG_TAG_INTERNAL, -1) \
295 << "Check failed: " << "\"" << (s1) << "\"" \
296 << ((sense) ? " == " : " != ") << "\"" << (s2) << "\""
300#define CHECK_STREQ(s1, s2) CHECK_STROP(s1, s2, true)
301#define CHECK_STRNE(s1, s2) CHECK_STROP(s1, s2, false)
304#define CHECK_PTHREAD_CALL(call, args, what) \
306 int rc = call args; \
309 ABORT_AFTER_LOG_FATAL \
310 PLOG(FATAL) << #call << " failed for " << (what); \
317#if defined(NDEBUG) && !defined(__clang_analyzer__)
324 if (::android::base::kEnableDChecks) CHECK(x)
325#define DCHECK_EQ(x, y) \
326 if (::android::base::kEnableDChecks) CHECK_EQ(x, y)
327#define DCHECK_NE(x, y) \
328 if (::android::base::kEnableDChecks) CHECK_NE(x, y)
329#define DCHECK_LE(x, y) \
330 if (::android::base::kEnableDChecks) CHECK_LE(x, y)
331#define DCHECK_LT(x, y) \
332 if (::android::base::kEnableDChecks) CHECK_LT(x, y)
333#define DCHECK_GE(x, y) \
334 if (::android::base::kEnableDChecks) CHECK_GE(x, y)
335#define DCHECK_GT(x, y) \
336 if (::android::base::kEnableDChecks) CHECK_GT(x, y)
337#define DCHECK_STREQ(s1, s2) \
338 if (::android::base::kEnableDChecks) CHECK_STREQ(s1, s2)
339#define DCHECK_STRNE(s1, s2) \
340 if (::android::base::kEnableDChecks) CHECK_STRNE(s1, s2)
342namespace log_detail {
346 template <
typename U>
explicit constexpr Storage(U&& u) :
v(
std::forward<U>(u)) {}
354 explicit constexpr Storage(
const std::unique_ptr<T>& ptr) :
v(ptr.get()) {}
358 explicit constexpr Storage(
const std::shared_ptr<T>& ptr) :
v(ptr.get()) {}
364 using Pointee = std::remove_cv_t<std::remove_pointer_t<T>>;
365 static constexpr bool value = std::is_pointer_v<T> &&
366 (std::is_same_v<Pointee, char> || std::is_same_v<Pointee, signed char> ||
367 std::is_same_v<Pointee, unsigned char>);
375 using LHSType = std::conditional_t<voidptr, const void*, LHS>;
376 using RHSType = std::conditional_t<voidptr, const void*, RHS>;
381template <
typename LHS,
typename RHS>
394 static const T&
Guard(
const T& v) {
return v; }
397 static const char*
Guard(
const std::nullptr_t&) {
return "(null)"; }
400 static const char*
Guard(
const char* v) {
return v ? v :
"(null)"; }
403 static const char*
Guard(
const char* v) {
return v ? v :
"(null)"; }
407template <
typename LHS,
typename RHS>
410 std::forward<LHS>(lhs), std::forward<RHS>(rhs));
433 static void LogLine(
const char* file,
unsigned int line,
LogSeverity severity,
const char* tag,
437 const std::unique_ptr<LogMessageData>
data_;
474#pragma clang diagnostic push
475#pragma clang diagnostic ignored "-Wgcc-compat"
476#define OSTREAM_STRING_POINTER_USAGE_WARNING \
477 __attribute__((diagnose_if(true, "Unexpected logging of string pointer", "warning")))
479std::ostream&
operator<<(std::ostream& stream,
const std::string* string_pointer) {
480 return stream << static_cast<const void*>(string_pointer);
482#pragma clang diagnostic pop
Definition: logging.h:419
std::ostream & stream()
Definition: logging.cpp:509
LogMessage(const char *file, unsigned int line, LogId, LogSeverity severity, const char *tag, int error)
Definition: logging.cpp:468
const std::unique_ptr< LogMessageData > data_
Definition: logging.h:437
~LogMessage()
Definition: logging.cpp:476
DISALLOW_COPY_AND_ASSIGN(LogMessage)
static void LogLine(const char *file, unsigned int line, LogSeverity severity, const char *tag, const char *msg)
Definition: logging.cpp:513
Definition: logging.h:133
LogdLogger(LogId default_log_id=android::base::MAIN)
Definition: logging.cpp:324
LogId default_log_id_
Definition: logging.h:141
void operator()(LogId, LogSeverity, const char *tag, const char *file, unsigned int line, const char *message)
Definition: logging.cpp:326
Definition: logging.h:452
LogSeverity old_
Definition: logging.h:458
~ScopedLogSeverity()
Definition: logging.cpp:569
ScopedLogSeverity(LogSeverity level)
Definition: logging.cpp:565
#define error(format, args...)
Definition: fec_private.h:201
#define OSTREAM_STRING_POINTER_USAGE_WARNING
Definition: logging.h:476
#define INIT_LOGGING_DEFAULT_LOGGER
Definition: logging.h:155
void KernelLogger(LogId log_buffer_id, LogSeverity severity, const char *tag, const char *file, unsigned int line, const char *message)
std::function< void(const char *)> AbortFunction
Definition: logging.h:111
constexpr auto MakeEagerEvaluator(LHS &&lhs, RHS &&rhs)
Definition: logging.h:408
static constexpr bool kEnableDChecks
Definition: logging.h:320
void StdioLogger(LogId log_buffer_id, LogSeverity severity, const char *tag, const char *file, unsigned int line, const char *message)
Definition: logging.cpp:290
AbortFunction SetAborter(AbortFunction &&aborter)
Definition: logging.cpp:409
std::function< void(LogId, LogSeverity, const char *, const char *, unsigned int, const char *)> LogFunction
Definition: logging.h:110
void SetDefaultTag(const std::string &tag)
Definition: logging.cpp:213
bool ShouldLog(LogSeverity severity, const char *tag)
Definition: logging.cpp:542
LogFunction SetLogger(LogFunction &&logger)
Definition: logging.cpp:393
LogSeverity SetMinimumLogSeverity(LogSeverity new_severity)
Definition: logging.cpp:554
LogSeverity GetMinimumLogSeverity()
Definition: logging.cpp:534
LogId
Definition: logging.h:97
@ CRASH
Definition: logging.h:102
@ SYSTEM
Definition: logging.h:100
@ RADIO
Definition: logging.h:101
@ DEFAULT
Definition: logging.h:98
@ MAIN
Definition: logging.h:99
void DefaultAborter(const char *abort_message)
Definition: logging.cpp:300
LogSeverity
Definition: logging.h:87
@ DEBUG
Definition: logging.h:89
@ WARNING
Definition: logging.h:91
@ FATAL_WITHOUT_ABORT
Definition: logging.h:93
@ INFO
Definition: logging.h:90
@ FATAL
Definition: logging.h:94
@ VERBOSE
Definition: logging.h:88
@ ERROR
Definition: logging.h:92
void InitLogging(char *argv[], LogFunction &&logger=INIT_LOGGING_DEFAULT_LOGGER, AbortFunction &&aborter=DefaultAborter)
Definition: logging.cpp:335
void StderrLogger(LogId log_buffer_id, LogSeverity severity, const char *tag, const char *file, unsigned int line, const char *message)
Definition: logging.cpp:280
Size< 0 > B
Definition: storage_literals.h:36
class incremental::File __attribute__
Definition: logging.h:464
OSTREAM_STRING_POINTER_USAGE_WARNING std::ostream & operator<<(std::ostream &stream, const std::string *string_pointer)
Definition: logging.h:479
static const char * Guard(const char *v)
Definition: logging.h:400
static const char * Guard(const char *v)
Definition: logging.h:403
static const char * Guard(const std::nullptr_t &)
Definition: logging.h:397
Definition: logging.h:393
static const T & Guard(const T &v)
Definition: logging.h:394
Definition: logging.h:382
const Storage< typename StorageTypes< LHS, RHS >::RHSType > rhs
Definition: logging.h:386
constexpr EagerEvaluator(A &&l, B &&r)
Definition: logging.h:383
const Storage< typename StorageTypes< LHS, RHS >::LHSType > lhs
Definition: logging.h:385
Definition: logging.h:363
static constexpr bool value
Definition: logging.h:365
std::remove_cv_t< std::remove_pointer_t< T > > Pointee
Definition: logging.h:364
Definition: logging.h:373
std::conditional_t< voidptr, const void *, RHS > RHSType
Definition: logging.h:376
static constexpr bool voidptr
Definition: logging.h:374
std::conditional_t< voidptr, const void *, LHS > LHSType
Definition: logging.h:375
constexpr Storage(const std::shared_ptr< T > &ptr)
Definition: logging.h:358
const T * v
Definition: logging.h:359
const T * v
Definition: logging.h:355
constexpr Storage(const std::unique_ptr< T > &ptr)
Definition: logging.h:354
Definition: logging.h:345
T v
Definition: logging.h:349
Storage(const Storage &t)=delete
Storage(Storage &&t)=delete
constexpr Storage(U &&u)
Definition: logging.h:346