17ec681f3Smrg/*
27ec681f3Smrg * Copyright (C) 2005-2017 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#include <android/log.h>
207ec681f3Smrg
217ec681f3Smrg/*
227ec681f3Smrg * Normally we strip the effects of ALOGV (VERBOSE messages),
237ec681f3Smrg * LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the
247ec681f3Smrg * release builds be defining NDEBUG.  You can modify this (for
257ec681f3Smrg * example with "#define LOG_NDEBUG 0" at the top of your source
267ec681f3Smrg * file) to change that behavior.
277ec681f3Smrg */
287ec681f3Smrg
297ec681f3Smrg#ifndef LOG_NDEBUG
307ec681f3Smrg#ifdef NDEBUG
317ec681f3Smrg#define LOG_NDEBUG 1
327ec681f3Smrg#else
337ec681f3Smrg#define LOG_NDEBUG 0
347ec681f3Smrg#endif
357ec681f3Smrg#endif
367ec681f3Smrg
377ec681f3Smrg#ifndef __predict_false
387ec681f3Smrg#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
397ec681f3Smrg#endif
407ec681f3Smrg
417ec681f3Smrg/*
427ec681f3Smrg * Simplified macro to send a verbose system log message using current LOG_TAG.
437ec681f3Smrg */
447ec681f3Smrg#ifndef SLOGV
457ec681f3Smrg#define __SLOGV(...)                                                          \
467ec681f3Smrg  ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, \
477ec681f3Smrg                                 __VA_ARGS__))
487ec681f3Smrg#if LOG_NDEBUG
497ec681f3Smrg#define SLOGV(...)          \
507ec681f3Smrg  do {                      \
517ec681f3Smrg    if (0) {                \
527ec681f3Smrg      __SLOGV(__VA_ARGS__); \
537ec681f3Smrg    }                       \
547ec681f3Smrg  } while (0)
557ec681f3Smrg#else
567ec681f3Smrg#define SLOGV(...) __SLOGV(__VA_ARGS__)
577ec681f3Smrg#endif
587ec681f3Smrg#endif
597ec681f3Smrg
607ec681f3Smrg#ifndef SLOGV_IF
617ec681f3Smrg#if LOG_NDEBUG
627ec681f3Smrg#define SLOGV_IF(cond, ...) ((void)0)
637ec681f3Smrg#else
647ec681f3Smrg#define SLOGV_IF(cond, ...)                                                 \
657ec681f3Smrg  ((__predict_false(cond))                                                  \
667ec681f3Smrg       ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, \
677ec681f3Smrg                                        LOG_TAG, __VA_ARGS__))              \
687ec681f3Smrg       : (void)0)
697ec681f3Smrg#endif
707ec681f3Smrg#endif
717ec681f3Smrg
727ec681f3Smrg/*
737ec681f3Smrg * Simplified macro to send a debug system log message using current LOG_TAG.
747ec681f3Smrg */
757ec681f3Smrg#ifndef SLOGD
767ec681f3Smrg#define SLOGD(...)                                                          \
777ec681f3Smrg  ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, \
787ec681f3Smrg                                 __VA_ARGS__))
797ec681f3Smrg#endif
807ec681f3Smrg
817ec681f3Smrg#ifndef SLOGD_IF
827ec681f3Smrg#define SLOGD_IF(cond, ...)                                               \
837ec681f3Smrg  ((__predict_false(cond))                                                \
847ec681f3Smrg       ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, \
857ec681f3Smrg                                        LOG_TAG, __VA_ARGS__))            \
867ec681f3Smrg       : (void)0)
877ec681f3Smrg#endif
887ec681f3Smrg
897ec681f3Smrg/*
907ec681f3Smrg * Simplified macro to send an info system log message using current LOG_TAG.
917ec681f3Smrg */
927ec681f3Smrg#ifndef SLOGI
937ec681f3Smrg#define SLOGI(...)                                                         \
947ec681f3Smrg  ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, \
957ec681f3Smrg                                 __VA_ARGS__))
967ec681f3Smrg#endif
977ec681f3Smrg
987ec681f3Smrg#ifndef SLOGI_IF
997ec681f3Smrg#define SLOGI_IF(cond, ...)                                              \
1007ec681f3Smrg  ((__predict_false(cond))                                               \
1017ec681f3Smrg       ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, \
1027ec681f3Smrg                                        LOG_TAG, __VA_ARGS__))           \
1037ec681f3Smrg       : (void)0)
1047ec681f3Smrg#endif
1057ec681f3Smrg
1067ec681f3Smrg/*
1077ec681f3Smrg * Simplified macro to send a warning system log message using current LOG_TAG.
1087ec681f3Smrg */
1097ec681f3Smrg#ifndef SLOGW
1107ec681f3Smrg#define SLOGW(...)                                                         \
1117ec681f3Smrg  ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, \
1127ec681f3Smrg                                 __VA_ARGS__))
1137ec681f3Smrg#endif
1147ec681f3Smrg
1157ec681f3Smrg#ifndef SLOGW_IF
1167ec681f3Smrg#define SLOGW_IF(cond, ...)                                              \
1177ec681f3Smrg  ((__predict_false(cond))                                               \
1187ec681f3Smrg       ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, \
1197ec681f3Smrg                                        LOG_TAG, __VA_ARGS__))           \
1207ec681f3Smrg       : (void)0)
1217ec681f3Smrg#endif
1227ec681f3Smrg
1237ec681f3Smrg/*
1247ec681f3Smrg * Simplified macro to send an error system log message using current LOG_TAG.
1257ec681f3Smrg */
1267ec681f3Smrg#ifndef SLOGE
1277ec681f3Smrg#define SLOGE(...)                                                          \
1287ec681f3Smrg  ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, \
1297ec681f3Smrg                                 __VA_ARGS__))
1307ec681f3Smrg#endif
1317ec681f3Smrg
1327ec681f3Smrg#ifndef SLOGE_IF
1337ec681f3Smrg#define SLOGE_IF(cond, ...)                                               \
1347ec681f3Smrg  ((__predict_false(cond))                                                \
1357ec681f3Smrg       ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, \
1367ec681f3Smrg                                        LOG_TAG, __VA_ARGS__))            \
1377ec681f3Smrg       : (void)0)
1387ec681f3Smrg#endif
139