1 /* 2 * Copyright (C) 2005-2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 /* Too many in the ecosystem assume these are included */ 20 #if !defined(_WIN32) 21 #include <pthread.h> 22 #endif 23 #include <stdint.h> /* uint16_t, int32_t */ 24 #include <stdio.h> 25 #include <time.h> 26 #include <unistd.h> 27 28 #include <android/log.h> 29 #include <log/log_id.h> 30 #include <log/log_main.h> 31 #include <log/log_radio.h> 32 #include <log/log_read.h> 33 #include <log/log_safetynet.h> 34 #include <log/log_system.h> 35 #include <log/log_time.h> 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 /* 42 * LOG_TAG is the local tag used for the following simplified 43 * logging macros. You can change this preprocessor definition 44 * before using the other macros to change the tag. 45 */ 46 47 #ifndef LOG_TAG 48 #define LOG_TAG NULL 49 #endif 50 51 /* 52 * Normally we strip the effects of ALOGV (VERBOSE messages), 53 * LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the 54 * release builds be defining NDEBUG. You can modify this (for 55 * example with "#define LOG_NDEBUG 0" at the top of your source 56 * file) to change that behavior. 57 */ 58 59 #ifndef LOG_NDEBUG 60 #ifdef NDEBUG 61 #define LOG_NDEBUG 1 62 #else 63 #define LOG_NDEBUG 0 64 #endif 65 #endif 66 67 /* 68 * Event logging. 69 */ 70 71 /* 72 * The following should not be used directly. 73 */ 74 75 int __android_log_bwrite(int32_t tag, const void* payload, size_t len); 76 int __android_log_btwrite(int32_t tag, char type, const void* payload, 77 size_t len); 78 int __android_log_bswrite(int32_t tag, const char* payload); 79 80 int __android_log_stats_bwrite(int32_t tag, const void* payload, size_t len); 81 82 #define android_bWriteLog(tag, payload, len) \ 83 __android_log_bwrite(tag, payload, len) 84 #define android_btWriteLog(tag, type, payload, len) \ 85 __android_log_btwrite(tag, type, payload, len) 86 87 /* 88 * Event log entry types. 89 */ 90 #ifndef __AndroidEventLogType_defined 91 #define __AndroidEventLogType_defined 92 typedef enum { 93 /* Special markers for android_log_list_element type */ 94 EVENT_TYPE_LIST_STOP = '\n', /* declare end of list */ 95 EVENT_TYPE_UNKNOWN = '?', /* protocol error */ 96 97 /* must match with declaration in java/android/android/util/EventLog.java */ 98 EVENT_TYPE_INT = 0, /* int32_t */ 99 EVENT_TYPE_LONG = 1, /* int64_t */ 100 EVENT_TYPE_STRING = 2, 101 EVENT_TYPE_LIST = 3, 102 EVENT_TYPE_FLOAT = 4, 103 } AndroidEventLogType; 104 #endif 105 #define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType) 106 #define typeof_AndroidEventLogType unsigned char 107 108 #ifndef LOG_EVENT_INT 109 #define LOG_EVENT_INT(_tag, _value) \ 110 { \ 111 int intBuf = _value; \ 112 (void)android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, sizeof(intBuf)); \ 113 } 114 #endif 115 #ifndef LOG_EVENT_LONG 116 #define LOG_EVENT_LONG(_tag, _value) \ 117 { \ 118 long long longBuf = _value; \ 119 (void)android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, sizeof(longBuf)); \ 120 } 121 #endif 122 #ifndef LOG_EVENT_FLOAT 123 #define LOG_EVENT_FLOAT(_tag, _value) \ 124 { \ 125 float floatBuf = _value; \ 126 (void)android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \ 127 sizeof(floatBuf)); \ 128 } 129 #endif 130 #ifndef LOG_EVENT_STRING 131 #define LOG_EVENT_STRING(_tag, _value) \ 132 (void)__android_log_bswrite(_tag, _value); 133 #endif 134 135 #ifdef __linux__ 136 137 clockid_t android_log_clockid(void); 138 139 #endif /* __linux__ */ 140 141 /* --------------------------------------------------------------------- */ 142 143 /* 144 * Release any logger resources (a new log write will immediately re-acquire) 145 * 146 * This is specifically meant to be used by Zygote to close open file descriptors after fork() 147 * and before specialization. O_CLOEXEC is used on file descriptors, so they will be closed upon 148 * exec() in normal use cases. 149 * 150 * Note that this is not safe to call from a multi-threaded program. 151 */ 152 void __android_log_close(void); 153 154 #ifdef __cplusplus 155 } 156 #endif 157