2 * Copyright (c) 2018 TOYOTA MOTOR CORPORATION
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __HMI_DEBUG_H__
18 #define __HMI_DEBUG_H__
33 LOG_LEVEL_MAX = LOG_LEVEL_DEBUG
36 #define __FILENAME__ \
37 (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
39 #define HMI_ERROR(prefix, args, ...) \
40 _HMI_LOG(LOG_LEVEL_ERROR, __FILENAME__, __FUNCTION__, __LINE__, prefix, \
42 #define HMI_WARNING(prefix, args, ...) \
43 _HMI_LOG(LOG_LEVEL_WARNING, __FILENAME__, __FUNCTION__, __LINE__, prefix, \
45 #define HMI_NOTICE(prefix, args, ...) \
46 _HMI_LOG(LOG_LEVEL_NOTICE, __FILENAME__, __FUNCTION__, __LINE__, prefix, \
48 #define HMI_INFO(prefix, args, ...) \
49 _HMI_LOG(LOG_LEVEL_INFO, __FILENAME__, __FUNCTION__, __LINE__, prefix, args, \
51 #define HMI_DEBUG(prefix, args, ...) \
52 _HMI_LOG(LOG_LEVEL_DEBUG, __FILENAME__, __FUNCTION__, __LINE__, prefix, \
55 static char ERROR_FLAG[6][20] = {"NONE", "ERROR", "WARNING",
56 "NOTICE", "INFO", "DEBUG"};
58 static void _HMI_LOG(enum LOG_LEVEL level,
65 const int log_level = (getenv("USE_HMI_DEBUG") == NULL)
67 : atoi(getenv("USE_HMI_DEBUG"));
68 if (log_level < level) {
76 clock_gettime(CLOCK_REALTIME, &tp);
77 time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
81 if (log == NULL || vasprintf(&message, log, args) < 0)
83 fprintf(stderr, "[%10.3f] [%s %s] [%s, %s(), Line:%d] >>> %s \n",
84 time / 1000.0, prefix, ERROR_FLAG[level], file, func, line, message);
89 #endif //__HMI_DEBUG_H__