1 /*
2 * Copyright (C) 2017-2019 NXP Semiconductors
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 #include <log/log.h>
18
19 #include "phOsal_Posix.h"
20
21 /*Global log level to filter the type of logs to be published*/
22 static phOsal_eLogLevel_t geLogLevel = PHOSAL_LOGLEVEL_NONE;
23
24 /**
25 * Logging levels
26 * This function set the type of logs to be enabled
27 *
28 * \param[in] eLogLevel Type of logs to be enabled(info,errors,debug,data)
29 *
30 */
phOsal_SetLogLevel(phOsal_eLogLevel_t eLogLevel)31 void phOsal_SetLogLevel(phOsal_eLogLevel_t eLogLevel) {
32 geLogLevel = eLogLevel;
33 phOsal_LogDebugU32h((const uint8_t*)"Osal>Log Level set to:",
34 (uint32_t)eLogLevel);
35 }
36
37 /**
38 * Log Error
39 * This function prints the error message specified
40 * appropriate log level for error needs to be enabled from phOsal_SetLogLevel
41 *
42 * \param[in] pbMsg defines Error log message to be printed
43 *
44 */
phOsal_LogError(const uint8_t * pbMsg)45 void phOsal_LogError(const uint8_t* pbMsg) {
46 if (geLogLevel >= PHOSAL_LOGLEVEL_ERROR) ALOGE("%s", pbMsg);
47 }
48
49 /**
50 * Log Error
51 * This function prints the error message specified along with 32bit value in
52 * Hex appropriate log level for error needs to be enabled from
53 * phOsal_SetLogLevel
54 *
55 * \param[in] pbMsg defines Error log message to be printed
56 * \param[in] wValue defines value to be printed
57 *
58 */
phOsal_LogErrorU32h(const uint8_t * pbMsg,uint32_t wValue)59 void phOsal_LogErrorU32h(const uint8_t* pbMsg, uint32_t wValue) {
60 if (geLogLevel >= PHOSAL_LOGLEVEL_ERROR) ALOGE("%s:0x%x", pbMsg, wValue);
61 }
62
63 /**
64 * Log Error
65 * This function prints the error message specified along with 32bit value in
66 * decimal appropriate log level for error needs to be enabled from
67 * phOsal_SetLogLevel
68 *
69 * \param[in] pbMsg defines Error log message to be printed
70 * \param[in] wValue defines value to be printed
71 */
phOsal_LogErrorU32d(const uint8_t * pbMsg,uint32_t wValue)72 void phOsal_LogErrorU32d(const uint8_t* pbMsg, uint32_t wValue) {
73 if (geLogLevel >= PHOSAL_LOGLEVEL_ERROR) ALOGE("%s:%d", pbMsg, wValue);
74 }
75
76 /**
77 * Log Error String
78 * This function prints the error message specified along with string
79 * appropriate log level for error needs to be enabled from phOsal_SetLogLevel
80 *
81 * \param[in] pbMsg defines Error log message to be printed
82 * \param[in] pbString defines pointer to string to be printed
83 */
phOsal_LogErrorString(const uint8_t * pbMsg,const uint8_t * pbString)84 void phOsal_LogErrorString(const uint8_t* pbMsg, const uint8_t* pbString) {
85 if (geLogLevel >= PHOSAL_LOGLEVEL_ERROR) ALOGE("%s:%s", pbMsg, pbString);
86 }
87
88 /**
89 * Log Information
90 * This function prints the information /warning specified
91 * appropriate log level for info needs to be enabled from phOsal_SetLogLevel
92 *
93 * \param[in] pbMsg defines log message to be printed
94 *
95 */
phOsal_LogInfo(const uint8_t * pbMsg)96 void phOsal_LogInfo(const uint8_t* pbMsg) {
97 if (geLogLevel >= PHOSAL_LOGLEVEL_INFO) ALOGI("%s", pbMsg);
98 }
99
100 /**
101 * Log Information
102 * This function prints the information /warning specified along with 32bit
103 * value in Hex appropriate log level for info needs to be enabled from
104 * phOsal_SetLogLevel
105 *
106 * \param[in] pbMsg defines log message to be printed
107 * \param[in] wValue defines value to be printed
108 *
109 */
phOsal_LogInfoU32h(const uint8_t * pbMsg,uint32_t wValue)110 void phOsal_LogInfoU32h(const uint8_t* pbMsg, uint32_t wValue) {
111 if (geLogLevel >= PHOSAL_LOGLEVEL_INFO) ALOGI("%s:0x%x", pbMsg, wValue);
112 }
113
114 /**
115 * Log Information
116 * This function prints the information /warning specified along with 32bit
117 * value in Hex appropriate log level for info needs to be enabled from
118 * phOsal_SetLogLevel
119 *
120 * \param[in] pbMsg defines log message to be printed
121 * \param[in] wValue1 defines value to be printed
122 * \param[in] wValue2 defines value to be printed
123 *
124 */
phOsal_LogInfoU32hh(const uint8_t * pbMsg,uint32_t wValue1,uint32_t wValue2)125 void phOsal_LogInfoU32hh(const uint8_t* pbMsg, uint32_t wValue1,
126 uint32_t wValue2) {
127 if (geLogLevel >= PHOSAL_LOGLEVEL_INFO)
128 ALOGI("%s:0x%x 0x%x", pbMsg, wValue1, wValue2);
129 }
130
131 /**
132 * Log Information
133 * This function prints the information /warning specified along with 32bit
134 * value in float appropriate log level for info needs to be enabled from
135 * phOsal_SetLogLevel
136 *
137 * \param[in] pbMsg defines log message to be printed
138 * \param[in] wValue defines value to be printed
139 *
140 */
phOsal_LogInfo32f(const uint8_t * pbMsg,float wValue)141 void phOsal_LogInfo32f(const uint8_t* pbMsg, float wValue) {
142 if (geLogLevel >= PHOSAL_LOGLEVEL_INFO) ALOGI("%s:%f", pbMsg, wValue);
143 }
144
145 /**
146 * Log Information
147 * This function prints the information /warning specified along with 32bit
148 * value in decimal appropriate log level for info needs to be enabled from
149 * phOsal_SetLogLevel
150 *
151 * \param[in] pbMsg defines log message to be printed
152 * \param[in] wValue defines value to be printed
153 *
154 */
phOsal_LogInfoU32d(const uint8_t * pbMsg,uint32_t wValue)155 void phOsal_LogInfoU32d(const uint8_t* pbMsg, uint32_t wValue) {
156 if (geLogLevel >= PHOSAL_LOGLEVEL_INFO) ALOGI("%s:%d", pbMsg, wValue);
157 }
158
159 /**
160 * Log Information
161 * This function prints the information / warning specified along with 32bit
162 * value in decimal appropriate log level for info needs to be enabled from
163 * phOsal_SetLogLevel
164 *
165 * \param[in] pbMsg defines log message to be printed
166 * \param[in] wValue1 defines value to be printed
167 * \param[in] wValue2 defines value to be printed
168 *
169 */
phOsal_LogInfoU32dd(const uint8_t * pbMsg,uint32_t wValue1,uint32_t wValue2)170 void phOsal_LogInfoU32dd(const uint8_t* pbMsg, uint32_t wValue1,
171 uint32_t wValue2) {
172 if (geLogLevel >= PHOSAL_LOGLEVEL_INFO)
173 ALOGI("%s:%d.%d", pbMsg, wValue1, wValue2);
174 }
175
176 /**
177 * Log Information and String
178 * This function prints the information specified along with string
179 * appropriate log level for info needs to be enabled from phOsal_SetLogLevel
180 *
181 * \param[in] pbMsg defines log message to be printed
182 * \param[in] pbString defines pointer to string to be printed
183 */
phOsal_LogInfoString(const uint8_t * pbMsg,const uint8_t * pbString)184 void phOsal_LogInfoString(const uint8_t* pbMsg, const uint8_t* pbString) {
185 if (geLogLevel >= PHOSAL_LOGLEVEL_INFO) ALOGI("%s:%s", pbMsg, pbString);
186 }
187
188 /**
189 * Log Debug Information
190 * This function prints the Debug log message specified
191 * appropriate log level for debug needs to be enabled from phOsal_SetLogLevel
192 *
193 * \param[in] pbMsg defines log message to be printed
194 *
195 */
phOsal_LogDebug(const uint8_t * pbMsg)196 void phOsal_LogDebug(const uint8_t* pbMsg) {
197 if (geLogLevel >= PHOSAL_LOGLEVEL_DEBUG) ALOGD("%s", pbMsg);
198 }
199
200 /**
201 * Log Debug Information
202 * This function prints the Debug log message specified along with 32bit value
203 * in hex appropriate log level for debug needs to be enabled from
204 * phOsal_SetLogLevel
205 *
206 * \param[in] pbMsg defines log message to be printed
207 * \param[in] wValue defines value to be printed
208 *
209 */
phOsal_LogDebugU32h(const uint8_t * pbMsg,uint32_t wValue)210 void phOsal_LogDebugU32h(const uint8_t* pbMsg, uint32_t wValue) {
211 if (geLogLevel >= PHOSAL_LOGLEVEL_DEBUG) ALOGD("%s:0x%X", pbMsg, wValue);
212 }
213
214 /**
215 * Log Debug Information
216 * This function prints the Debug log message specified along with 32bit value
217 * in decimal appropriate log level for debug needs to be enabled from
218 * phOsal_SetLogLevel
219 *
220 * \param[in] pbMsg defines log message to be printed
221 * \param[in] wValue defines value to be printed
222 *
223 */
phOsal_LogDebugU32d(const uint8_t * pbMsg,uint32_t wValue)224 void phOsal_LogDebugU32d(const uint8_t* pbMsg, uint32_t wValue) {
225 if (geLogLevel >= PHOSAL_LOGLEVEL_DEBUG) ALOGD("%s:%d", pbMsg, wValue);
226 }
227
228 /**
229 * Log Debug Information
230 * This function prints the Debug log message specified along with pointer value
231 * in hex appropriate log level for debug needs to be enabled from
232 * phOsal_SetLogLevel
233 *
234 * \param[in] pbMsg defines log message to be printed
235 * \param[in] pValue defines value to be printed
236 *
237 */
phOsal_LogDebugPtrh(const uint8_t * pbMsg,void * pValue)238 void phOsal_LogDebugPtrh(const uint8_t* pbMsg, void* pValue) {
239 if (geLogLevel >= PHOSAL_LOGLEVEL_DEBUG) ALOGD("%s:0x%p", pbMsg, pValue);
240 }
241
242 /**
243 * Log Debug Information specified along with the string
244 * This function prints the Debug log message specified along with 32bit value
245 * in decimal appropriate log level for debug needs to be enabled from
246 * phOsal_SetLogLevel
247 *
248 * \param[in] pbMsg defines log message to be printed
249 * \param[in] wValue defines value to be printed
250 *
251 */
phOsal_LogDebugString(const uint8_t * pbMsg,const uint8_t * pbString)252 void phOsal_LogDebugString(const uint8_t* pbMsg, const uint8_t* pbString) {
253 if (geLogLevel >= PHOSAL_LOGLEVEL_DEBUG) ALOGD("%s:%s", pbMsg, pbString);
254 }
255
256 /**
257 * Log Buffer data
258 * This function prints the data in the buffers provided in Hex
259 * appropriate log level for debug needs to be enabled from phOsal_SetLogLevel
260 *
261 * \param[in] pbBuffer Buffer data to be logged
262 * \param[in] dwSizeOfBuffer Size of buffer data.
263 * \param[in] pbMsg defines message to be printed before
264 * printing the buffer data.
265 *
266 */
phOsal_LogBuffer(const uint8_t * pbBuffer,uint32_t dwSizeOfBuffer,const uint8_t * pbMsg)267 void phOsal_LogBuffer(const uint8_t* pbBuffer, uint32_t dwSizeOfBuffer,
268 const uint8_t* pbMsg) {
269 if (geLogLevel >= PHOSAL_LOGLEVEL_DATA_BUFFERS) {
270 uint32_t i = 0;
271 ALOGD("%s:BufSize=%d:", pbMsg, dwSizeOfBuffer);
272 for (i = 0; i < dwSizeOfBuffer; i++) ALOGD("0x%0.2X", pbBuffer[i]);
273 }
274 }
275
276 /**
277 * Log function entry point
278 * This function prints the function name specified prefixed by Module name
279 * appropriate log level for debug needs to be enabled from phOsal_SetLogLevel
280 *
281 * \param[in] pbModuleName defines log message to be printed
282 * \param[in] pbFuncName defines value to be printed
283 *
284 */
phOsal_LogFunctionEntry(const uint8_t * pbModuleName,const uint8_t * pbFuncName)285 void phOsal_LogFunctionEntry(const uint8_t* pbModuleName,
286 const uint8_t* pbFuncName) {
287 if (geLogLevel >= PHOSAL_LOGLEVEL_DEBUG)
288 ALOGD("%s>%s:Enter", pbModuleName, pbFuncName);
289 }
290
291 /**
292 * Log function exit point
293 * This function prints the function name specified prefixed by Module name
294 * appropriate log level for debug needs to be enabled from phOsal_SetLogLevel
295 *
296 * \param[in] pbMsg defines log message to be printed
297 * \param[in] wValue defines value to be printed
298 *
299 */
phOsal_LogFunctionExit(const uint8_t * pbModuleName,const uint8_t * pbFuncName)300 void phOsal_LogFunctionExit(const uint8_t* pbModuleName,
301 const uint8_t* pbFuncName) {
302 if (geLogLevel >= PHOSAL_LOGLEVEL_DEBUG)
303 ALOGD("%s>%s:Exit", pbModuleName, pbFuncName);
304 }
305