• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <sys/types.h>
26 #include <time.h>
27 #include <unistd.h>
28 
29 #include <android/log.h>
30 #include <log/log_id.h>
31 #include <log/log_main.h>
32 #include <log/log_radio.h>
33 #include <log/log_read.h>
34 #include <log/log_safetynet.h>
35 #include <log/log_system.h>
36 #include <log/log_time.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * LOG_TAG is the local tag used for the following simplified
44  * logging macros.  You can change this preprocessor definition
45  * before using the other macros to change the tag.
46  */
47 
48 #ifndef LOG_TAG
49 #define LOG_TAG NULL
50 #endif
51 
52 /*
53  * Normally we strip the effects of ALOGV (VERBOSE messages),
54  * LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the
55  * release builds be defining NDEBUG.  You can modify this (for
56  * example with "#define LOG_NDEBUG 0" at the top of your source
57  * file) to change that behavior.
58  */
59 
60 #ifndef LOG_NDEBUG
61 #ifdef NDEBUG
62 #define LOG_NDEBUG 1
63 #else
64 #define LOG_NDEBUG 0
65 #endif
66 #endif
67 
68 /* --------------------------------------------------------------------- */
69 
70 /*
71  * This file uses ", ## __VA_ARGS__" zero-argument token pasting to
72  * work around issues with debug-only syntax errors in assertions
73  * that are missing format strings.  See commit
74  * 19299904343daf191267564fe32e6cd5c165cd42
75  */
76 #if defined(__clang__)
77 #pragma clang diagnostic push
78 #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
79 #endif
80 
81 /* --------------------------------------------------------------------- */
82 
83 /*
84  * Event logging.
85  */
86 
87 /*
88  * The following should not be used directly.
89  */
90 
91 int __android_log_bwrite(int32_t tag, const void* payload, size_t len);
92 int __android_log_btwrite(int32_t tag, char type, const void* payload,
93                           size_t len);
94 int __android_log_bswrite(int32_t tag, const char* payload);
95 
96 int __android_log_stats_bwrite(int32_t tag, const void* payload, size_t len);
97 
98 #define android_bWriteLog(tag, payload, len) \
99   __android_log_bwrite(tag, payload, len)
100 #define android_btWriteLog(tag, type, payload, len) \
101   __android_log_btwrite(tag, type, payload, len)
102 
103 /*
104  * Event log entry types.
105  */
106 #ifndef __AndroidEventLogType_defined
107 #define __AndroidEventLogType_defined
108 typedef enum {
109   /* Special markers for android_log_list_element type */
110   EVENT_TYPE_LIST_STOP = '\n', /* declare end of list  */
111   EVENT_TYPE_UNKNOWN = '?',    /* protocol error       */
112 
113   /* must match with declaration in java/android/android/util/EventLog.java */
114   EVENT_TYPE_INT = 0,  /* int32_t */
115   EVENT_TYPE_LONG = 1, /* int64_t */
116   EVENT_TYPE_STRING = 2,
117   EVENT_TYPE_LIST = 3,
118   EVENT_TYPE_FLOAT = 4,
119 } AndroidEventLogType;
120 #endif
121 #define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
122 #define typeof_AndroidEventLogType unsigned char
123 
124 #ifndef LOG_EVENT_INT
125 #define LOG_EVENT_INT(_tag, _value)                                          \
126   {                                                                          \
127     int intBuf = _value;                                                     \
128     (void)android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, sizeof(intBuf)); \
129   }
130 #endif
131 #ifndef LOG_EVENT_LONG
132 #define LOG_EVENT_LONG(_tag, _value)                                            \
133   {                                                                             \
134     long long longBuf = _value;                                                 \
135     (void)android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, sizeof(longBuf)); \
136   }
137 #endif
138 #ifndef LOG_EVENT_FLOAT
139 #define LOG_EVENT_FLOAT(_tag, _value)                           \
140   {                                                             \
141     float floatBuf = _value;                                    \
142     (void)android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \
143                              sizeof(floatBuf));                 \
144   }
145 #endif
146 #ifndef LOG_EVENT_STRING
147 #define LOG_EVENT_STRING(_tag, _value) \
148   (void)__android_log_bswrite(_tag, _value);
149 #endif
150 
151 #ifdef __linux__
152 
153 clockid_t android_log_clockid(void);
154 
155 #endif /* __linux__ */
156 
157 /* --------------------------------------------------------------------- */
158 
159 /*
160  * Release any logger resources (a new log write will immediately re-acquire)
161  *
162  * May be used to clean up File descriptors after a Fork, the resources are
163  * all O_CLOEXEC so wil self clean on exec().
164  */
165 void __android_log_close(void);
166 
167 #if defined(__clang__)
168 #pragma clang diagnostic pop
169 #endif
170 
171 #ifdef __cplusplus
172 }
173 #endif
174