1 /******************************************************************
3 * Copyright 2020 Samsung Electronics All Rights Reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************/
25 #define UNUSED __attribute__((unused))
27 extern int __log_level;
28 extern void dcm_print(int priority, char const *fmt, ...);
31 template <typename ...Args>
32 void UNUSED __LOG_FUN(int level, const std::stringstream &format, Args&&... args) {
33 dcm_print(level, format.str().c_str(), std::forward<Args>(args)...);
37 void UNUSED __LOG_FUN(int level, const std::stringstream &format) {
38 dcm_print(level, "%s", format.str().c_str());
41 template <typename ...Args>
42 void UNUSED __LOG_FUN(int level, const char *format, Args&&... args) {
43 dcm_print(level, format, std::forward<Args>(args)...);
47 void UNUSED __LOG_FUN(int level, const char *format) {
48 dcm_print(level, "%s", format);
51 } // namespace anonymous
53 #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
55 #define __LOG(LEVEL, FORMAT, ...) \
57 if (LEVEL <= __log_level) { \
58 std::stringstream __LOG_FORMAT; \
59 __LOG_FORMAT << __FILENAME__ << ": " << __func__ << "(" << __LINE__ << ") > " << FORMAT; \
60 __LOG_FUN(LEVEL, __LOG_FORMAT, ##__VA_ARGS__); \
64 #define LOGM(...) __LOG(LOG_EMERG, __VA_ARGS__) /* system is unusable */
65 #define LOGE(...) __LOG(LOG_ERR, __VA_ARGS__) /* error conditions */
66 #define LOGW(...) __LOG(LOG_WARNING, __VA_ARGS__) /* warning conditions */
67 #define LOGI(...) __LOG(LOG_INFO, __VA_ARGS__) /* informational */
68 #define LOGD(...) __LOG(LOG_DEBUG, __VA_ARGS__) /* debug-level messages */
70 #endif /* SHARED_LOG_H_ */