• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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  * Android logging wrapper to make it easy to interchange based on environment.
17  */
18 
19 #ifndef ESE_LOG_H_
20 #define ESE_LOG_H_ 1
21 
22 /* Uncomment when doing bring up or other messy debugging.
23  * #define LOG_NDEBUG 0
24  */
25 
26 #if defined(ESE_LOG_NONE) || defined(ESE_LOG_STDIO)
27 #  define ESE_LOG_ANDROID 0
28 #endif
29 
30 #if !defined(ESE_LOG_ANDROID)
31 #define ESE_LOG_ANDROID 1
32 #endif
33 
34 #if !defined(LOG_TAG)
35 #  define LOG_TAG "libese"
36 #endif
37 
38 #if ESE_LOG_ANDROID == 1
39 
40 #include <log/log.h>
41 
42 #else  /* ESE_LOG_ANDROID */
43 
44 #ifndef ALOGV
45 #define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
46 #if LOG_NDEBUG
47 #define ALOGV(...) do { if (0) { __ALOGV(__VA_ARGS__); } } while (0)
48 #else
49 #define ALOGV(...) __ALOGV(__VA_ARGS__)
50 #endif
51 #endif
52 
53 #ifndef ALOGD
54 #define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
55 #endif
56 
57 #ifndef ALOGI
58 #define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
59 #endif
60 
61 #ifndef ALOGW
62 #define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
63 #endif
64 
65 #ifndef ALOGE
66 #define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
67 #endif
68 
69 #if defined(ESE_LOG_STDIO)
70 #include <stdio.h>
71 #include <stdlib.h>
72 #define ALOG(priority, tag, format, ...) \
73   fprintf(stderr, "[%s: %s] " format "\n", #priority, tag, ##__VA_ARGS__)
74 #define LOG_ALWAYS_FATAL(format, ...) { \
75   ALOG(LOG_ERROR, LOG_TAG, format, ##__VA_ARGS__);  \
76   abort(); \
77 }
78 
79 #elif defined(ESE_LOG_NONE)
80   #define ALOG(...) {}
81   #define LOG_ALWAYS_FATAL(...) while (1);
82 #endif
83 
84 #endif  /* !ESE_LOG_ANDROID */
85 
86 #endif  /* ESE_LOG_H_ */
87