1 // Copyright 2017 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. 4 5 #ifndef LOGGING_H_ 6 #define LOGGING_H_ 7 8 #include <android/log.h> 9 #include <errno.h> 10 #include <stdio.h> 11 #include <stdlib.h> 12 #include <string.h> 13 14 #define CHECK_ARGS(COND, ERR) \ 15 "FAILED CHECK(%s) @ %s:%d (errno: %s)\n", #COND, __FILE__, __LINE__, \ 16 strerror(ERR) 17 18 #define CHECK(x) \ 19 do { \ 20 if (!(x)) { \ 21 const int e = errno; \ 22 __android_log_print(ANDROID_LOG_FATAL, "atrace_helper", \ 23 CHECK_ARGS(x, e)); \ 24 fprintf(stderr, "\n" CHECK_ARGS(x, e)); \ 25 fflush(stderr); \ 26 abort(); \ 27 } \ 28 } while (0) 29 30 inline void LogError(const char* message) { 31 __android_log_write(ANDROID_LOG_ERROR, "atrace_helper", message); 32 fprintf(stderr, "\n%s\n", message); 33 fflush(stderr); 34 } 35 36 #endif // LOGGING_H_ 37