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