• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2014 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 /*
22  * TODO(armansito): Work-around until we figure out a way to generate logs in a
23  * platform-independent manner.
24  */
25 #if defined(OS_GENERIC)
26 
27 /* syslog didn't work well here since we would be redefining LOG_DEBUG. */
28 #include <stdio.h>
29 
30 #define LOGWRAPPER(tag, fmt, args...) \
31   fprintf(stderr, "%s: " fmt "\n", tag, ##args)
32 
33 #define LOG_VERBOSE(...) LOGWRAPPER(__VA_ARGS__)
34 #define LOG_DEBUG(...) LOGWRAPPER(__VA_ARGS__)
35 #define LOG_INFO(...) LOGWRAPPER(__VA_ARGS__)
36 #define LOG_WARN(...) LOGWRAPPER(__VA_ARGS__)
37 #define LOG_ERROR(...) LOGWRAPPER(__VA_ARGS__)
38 
39 #define LOG_EVENT_INT(...)
40 
41 #else /* !defined(OS_GENERIC) */
42 
43 #include <log/log.h>
44 
45 /**
46  * These log statements are effectively executing only ALOG(_________, tag, fmt,
47  * ## args ).
48  * fprintf is only to cause compilation error when LOG_TAG is not provided,
49  * which breaks build on Linux (for OS_GENERIC).
50  */
51 
52 #if LOG_NDEBUG
53 #define LOG_VERBOSE(tag, fmt, args...)                          \
54   do {                                                          \
55     (true) ? ((int)0) : fprintf(stderr, "%s" fmt, tag, ##args); \
56   } while (0)
57 #else  // LOG_NDEBUG
58 #define LOG_VERBOSE(tag, fmt, args...)               \
59   do {                                               \
60     (true) ? ALOG(LOG_VERBOSE, tag, fmt, ##args)     \
61            : fprintf(stderr, "%s" fmt, tag, ##args); \
62   } while (0)
63 #endif  // !LOG_NDEBUG
64 
65 #define LOG_DEBUG(tag, fmt, args...)                 \
66   do {                                               \
67     (true) ? ALOG(LOG_DEBUG, tag, fmt, ##args)       \
68            : fprintf(stderr, "%s" fmt, tag, ##args); \
69   } while (0)
70 #define LOG_INFO(tag, fmt, args...)                  \
71   do {                                               \
72     (true) ? ALOG(LOG_INFO, tag, fmt, ##args)        \
73            : fprintf(stderr, "%s" fmt, tag, ##args); \
74   } while (0)
75 #define LOG_WARN(tag, fmt, args...)                  \
76   do {                                               \
77     (true) ? ALOG(LOG_WARN, tag, fmt, ##args)        \
78            : fprintf(stderr, "%s" fmt, tag, ##args); \
79   } while (0)
80 #define LOG_ERROR(tag, fmt, args...)                 \
81   do {                                               \
82     (true) ? ALOG(LOG_ERROR, tag, fmt, ##args)       \
83            : fprintf(stderr, "%s" fmt, tag, ##args); \
84   } while (0)
85 
86 #endif /* defined(OS_GENERIC) */
87