• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2019 Google, Inc.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #pragma once
20 
21 #ifndef LOG_TAG
22 #define LOG_TAG "bt"
23 #endif
24 
25 #if defined(OS_ANDROID)
26 
27 #include <log/log.h>
28 
29 #define LOG_VERBOSE(fmt, args...) ALOGV("%s: " fmt, __PRETTY_FUNCTION__, ##args)
30 #define LOG_DEBUG(fmt, args...) ALOGD("%s: " fmt, __PRETTY_FUNCTION__, ##args)
31 #define LOG_INFO(fmt, args...) ALOGI("%s: " fmt, __PRETTY_FUNCTION__, ##args)
32 #define LOG_WARN(fmt, args...) ALOGW("%s: " fmt, __PRETTY_FUNCTION__, ##args)
33 #define LOG_ERROR(fmt, args...) ALOGE("%s: " fmt, __PRETTY_FUNCTION__, ##args)
34 
35 #else
36 
37 /* syslog didn't work well here since we would be redefining LOG_DEBUG. */
38 #include <stdio.h>
39 
40 #define LOGWRAPPER(fmt, args...) \
41   fprintf(stderr, "%s - %s: " fmt "\n", LOG_TAG, __PRETTY_FUNCTION__, ##args)
42 
43 #define LOG_VERBOSE(...) LOGWRAPPER(__VA_ARGS__)
44 #define LOG_DEBUG(...) LOGWRAPPER(__VA_ARGS__)
45 #define LOG_INFO(...) LOGWRAPPER(__VA_ARGS__)
46 #define LOG_WARN(...) LOGWRAPPER(__VA_ARGS__)
47 #define LOG_ERROR(...) LOGWRAPPER(__VA_ARGS__)
48 
49 #endif /* defined(OS_ANDROID) */
50 
51 #define ASSERT(condition) \
52   if (!(condition)) { \
53     LOG_ERROR("%s:%d assertion '" #condition "' failed", __FILE__, __LINE__); \
54     abort(); \
55   }
56 
57 #define ASSERT_LOG(condition, fmt, args...) \
58   if (!(condition)) { \
59     LOG_ERROR("%s:%d assertion '" #condition "' failed - " fmt, __FILE__, __LINE__, ##args); \
60     abort(); \
61   }
62 
63