17ec681f3Smrg/*
27ec681f3Smrg * Copyright (C) 2005-2014 The Android Open Source Project
37ec681f3Smrg *
47ec681f3Smrg * Licensed under the Apache License, Version 2.0 (the "License");
57ec681f3Smrg * you may not use this file except in compliance with the License.
67ec681f3Smrg * You may obtain a copy of the License at
77ec681f3Smrg *
87ec681f3Smrg *      http://www.apache.org/licenses/LICENSE-2.0
97ec681f3Smrg *
107ec681f3Smrg * Unless required by applicable law or agreed to in writing, software
117ec681f3Smrg * distributed under the License is distributed on an "AS IS" BASIS,
127ec681f3Smrg * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137ec681f3Smrg * See the License for the specific language governing permissions and
147ec681f3Smrg * limitations under the License.
157ec681f3Smrg */
167ec681f3Smrg
177ec681f3Smrg#pragma once
187ec681f3Smrg
197ec681f3Smrg/* Too many in the ecosystem assume these are included */
207ec681f3Smrg#if !defined(_WIN32)
217ec681f3Smrg#include <pthread.h>
227ec681f3Smrg#endif
237ec681f3Smrg#include <stdint.h> /* uint16_t, int32_t */
247ec681f3Smrg#include <stdio.h>
257ec681f3Smrg#include <time.h>
267ec681f3Smrg#include <unistd.h>
277ec681f3Smrg
287ec681f3Smrg#include <android/log.h>
297ec681f3Smrg#include <log/log_id.h>
307ec681f3Smrg#include <log/log_main.h>
317ec681f3Smrg#include <log/log_radio.h>
327ec681f3Smrg#include <log/log_safetynet.h>
337ec681f3Smrg#include <log/log_system.h>
347ec681f3Smrg#include <log/log_time.h>
357ec681f3Smrg
367ec681f3Smrg#ifdef __cplusplus
377ec681f3Smrgextern "C" {
387ec681f3Smrg#endif
397ec681f3Smrg
407ec681f3Smrg/*
417ec681f3Smrg * LOG_TAG is the local tag used for the following simplified
427ec681f3Smrg * logging macros.  You can change this preprocessor definition
437ec681f3Smrg * before using the other macros to change the tag.
447ec681f3Smrg */
457ec681f3Smrg
467ec681f3Smrg#ifndef LOG_TAG
477ec681f3Smrg#define LOG_TAG NULL
487ec681f3Smrg#endif
497ec681f3Smrg
507ec681f3Smrg/*
517ec681f3Smrg * Normally we strip the effects of ALOGV (VERBOSE messages),
527ec681f3Smrg * LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the
537ec681f3Smrg * release builds be defining NDEBUG.  You can modify this (for
547ec681f3Smrg * example with "#define LOG_NDEBUG 0" at the top of your source
557ec681f3Smrg * file) to change that behavior.
567ec681f3Smrg */
577ec681f3Smrg
587ec681f3Smrg#ifndef LOG_NDEBUG
597ec681f3Smrg#ifdef NDEBUG
607ec681f3Smrg#define LOG_NDEBUG 1
617ec681f3Smrg#else
627ec681f3Smrg#define LOG_NDEBUG 0
637ec681f3Smrg#endif
647ec681f3Smrg#endif
657ec681f3Smrg
667ec681f3Smrg/*
677ec681f3Smrg * The maximum size of the log entry payload that can be
687ec681f3Smrg * written to the logger. An attempt to write more than
697ec681f3Smrg * this amount will result in a truncated log entry.
707ec681f3Smrg */
717ec681f3Smrg#define LOGGER_ENTRY_MAX_PAYLOAD 4068
727ec681f3Smrg
737ec681f3Smrg/*
747ec681f3Smrg * Event logging.
757ec681f3Smrg */
767ec681f3Smrg
777ec681f3Smrg/*
787ec681f3Smrg * The following should not be used directly.
797ec681f3Smrg */
807ec681f3Smrg
817ec681f3Smrgint __android_log_bwrite(int32_t tag, const void* payload, size_t len);
827ec681f3Smrgint __android_log_btwrite(int32_t tag, char type, const void* payload,
837ec681f3Smrg                          size_t len);
847ec681f3Smrgint __android_log_bswrite(int32_t tag, const char* payload);
857ec681f3Smrg
867ec681f3Smrgint __android_log_stats_bwrite(int32_t tag, const void* payload, size_t len);
877ec681f3Smrg
887ec681f3Smrg#define android_bWriteLog(tag, payload, len) \
897ec681f3Smrg  __android_log_bwrite(tag, payload, len)
907ec681f3Smrg#define android_btWriteLog(tag, type, payload, len) \
917ec681f3Smrg  __android_log_btwrite(tag, type, payload, len)
927ec681f3Smrg
937ec681f3Smrg/*
947ec681f3Smrg * Event log entry types.
957ec681f3Smrg */
967ec681f3Smrgtypedef enum {
977ec681f3Smrg  /* Special markers for android_log_list_element type */
987ec681f3Smrg  EVENT_TYPE_LIST_STOP = '\n', /* declare end of list  */
997ec681f3Smrg  EVENT_TYPE_UNKNOWN = '?',    /* protocol error       */
1007ec681f3Smrg
1017ec681f3Smrg  /* must match with declaration in java/android/android/util/EventLog.java */
1027ec681f3Smrg  EVENT_TYPE_INT = 0,  /* int32_t */
1037ec681f3Smrg  EVENT_TYPE_LONG = 1, /* int64_t */
1047ec681f3Smrg  EVENT_TYPE_STRING = 2,
1057ec681f3Smrg  EVENT_TYPE_LIST = 3,
1067ec681f3Smrg  EVENT_TYPE_FLOAT = 4,
1077ec681f3Smrg} AndroidEventLogType;
1087ec681f3Smrg
1097ec681f3Smrg#ifndef LOG_EVENT_INT
1107ec681f3Smrg#define LOG_EVENT_INT(_tag, _value)                                          \
1117ec681f3Smrg  {                                                                          \
1127ec681f3Smrg    int intBuf = _value;                                                     \
1137ec681f3Smrg    (void)android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, sizeof(intBuf)); \
1147ec681f3Smrg  }
1157ec681f3Smrg#endif
1167ec681f3Smrg#ifndef LOG_EVENT_LONG
1177ec681f3Smrg#define LOG_EVENT_LONG(_tag, _value)                                            \
1187ec681f3Smrg  {                                                                             \
1197ec681f3Smrg    long long longBuf = _value;                                                 \
1207ec681f3Smrg    (void)android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, sizeof(longBuf)); \
1217ec681f3Smrg  }
1227ec681f3Smrg#endif
1237ec681f3Smrg#ifndef LOG_EVENT_FLOAT
1247ec681f3Smrg#define LOG_EVENT_FLOAT(_tag, _value)                           \
1257ec681f3Smrg  {                                                             \
1267ec681f3Smrg    float floatBuf = _value;                                    \
1277ec681f3Smrg    (void)android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \
1287ec681f3Smrg                             sizeof(floatBuf));                 \
1297ec681f3Smrg  }
1307ec681f3Smrg#endif
1317ec681f3Smrg#ifndef LOG_EVENT_STRING
1327ec681f3Smrg#define LOG_EVENT_STRING(_tag, _value) \
1337ec681f3Smrg  (void)__android_log_bswrite(_tag, _value);
1347ec681f3Smrg#endif
1357ec681f3Smrg
1367ec681f3Smrg/* --------------------------------------------------------------------- */
1377ec681f3Smrg
1387ec681f3Smrg/*
1397ec681f3Smrg * Release any logger resources (a new log write will immediately re-acquire)
1407ec681f3Smrg *
1417ec681f3Smrg * This is specifically meant to be used by Zygote to close open file descriptors after fork()
1427ec681f3Smrg * and before specialization.  O_CLOEXEC is used on file descriptors, so they will be closed upon
1437ec681f3Smrg * exec() in normal use cases.
1447ec681f3Smrg *
1457ec681f3Smrg * Note that this is not safe to call from a multi-threaded program.
1467ec681f3Smrg */
1477ec681f3Smrgvoid __android_log_close(void);
1487ec681f3Smrg
1497ec681f3Smrg#ifdef __cplusplus
1507ec681f3Smrg}
1517ec681f3Smrg#endif
152