1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#ifndef FILLP_LOG_H 17#define FILLP_LOG_H 18 19#include "fillp_os.h" 20#include "opt.h" 21 22#ifdef __cplusplus 23extern "C" { 24#endif 25 26#ifdef FILLP_LINUX 27 28#ifdef PDT_UT 29 30/* for UT statement coverage */ 31#define FILLP_LOG_IN(_level, _type, _pre, fmt, ...) 32 33#else 34 35#if FILLP_LOG_WITH_TIME 36 37static inline void FillpLogGetNowTime(struct timeval *tv, struct tm *nowTime) 38{ 39 (void)gettimeofday(tv, FILLP_NULL_PTR); 40 time_t sec = (time_t)tv->tv_sec; 41 (void)localtime_r(&sec, nowTime); 42} 43 44#define FILLP_LM_LOG_OUTPUT(_type, _level, _pre, fmt, ...) do { \ 45 struct timeval tv; \ 46 struct tm nowTime; \ 47 FillpLogGetNowTime(&tv, &nowTime); \ 48 (*g_fillpLmGlobal.lmCallbackFn.debugCallbackFunc)(_type, _level, 0, \ 49 "%02d%02d %02d:%02d:%02d.%06ld %s:[%d] : <%s>" fmt "\r\n", \ 50 nowTime.tm_mon + 1, nowTime.tm_mday, nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec, \ 51 (long)tv.tv_usec, __func__, __LINE__, _pre, ##__VA_ARGS__); \ 52 } while (0) 53 54#else 55 56#define FILLP_LM_LOG_OUTPUT(_type, _level, _pre, fmt, ...) ((*g_fillpLmGlobal.lmCallbackFn.debugCallbackFunc)( \ 57 _type, _level, 0, "%s:[%d] : <%s>" fmt "\r\n", __func__, __LINE__, _pre, ##__VA_ARGS__)) 58 59#endif /* FILLP_LOG_WITH_TIME */ 60 61#define FILLP_LOG_IN(_level, _type, _pre, fmt, ...) \ 62 do { \ 63 if ((_level) >= g_fillpLmGlobal.debugLevel && \ 64 (g_fillpLmGlobal.lmCallbackFn.debugCallbackFunc != FILLP_NULL_PTR)) { \ 65 FILLP_LM_LOG_OUTPUT(_type, _level, _pre, fmt, ##__VA_ARGS__); \ 66 } \ 67 } while (0) 68 69#endif 70 71#else 72 73#define FILLP_LOG_IN(_level, _type, _pre, fmt, ...) 74 75#endif /* FILLP_LINUX */ 76 77#define FILLP_LOGERR(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_ERROR, FILLP_DBG_LOG, "F-LOGERR", fmt, ##__VA_ARGS__) 78 79#define FILLP_LOGWAR(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_WARNING, FILLP_DBG_LOG, "F-LOGWAR", fmt, ##__VA_ARGS__) 80 81#define FILLP_LOGINF(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_INFO, FILLP_DBG_LOG, "F-LOGINF", fmt, ##__VA_ARGS__) 82 83#define FILLP_LOGDTL(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_DETAIL, FILLP_DBG_LOG, "F-LOGDTL", fmt, ##__VA_ARGS__) 84 85#define FILLP_LOGDBG(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_DEBUG, FILLP_DBG_LOG, "F-LOGDBG", fmt, ##__VA_ARGS__) 86 87#define FILLP_LOGBUTT(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_BUTT, FILLP_DBG_LOG, "F-LOGBUTT", fmt, ##__VA_ARGS__) 88 89#define FILLP_HELPBUTT(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_BUTT, FILLP_DBG_HELP, "F-HELPBUTT", fmt, ##__VA_ARGS__) 90 91#define FILLP_SHOWDATABUTT(fmt, ...) \ 92 FILLP_LOG_IN(FILLP_DBG_LVL_BUTT, FILLP_DBG_SHOW_DATA, "F-SHOWDATABUTT", fmt, ##__VA_ARGS__) 93 94#define FILLP_SHOWLEVELBUTT(fmt, ...) \ 95 FILLP_LOG_IN(FILLP_DBG_LVL_BUTT, FILLP_DBG_SHOW_LEVEL, "F-SHOWLEVELBUTT", fmt, ##__VA_ARGS__) 96 97#ifdef FILLP_MGT_MSG_LOG 98#define FILLP_LOGMGTMSG(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_INFO, FILLP_DBG_LOG, "F-LOGMGTMSG", fmt, ##__VA_ARGS__) 99#endif 100 101FILLP_INT FillpApiSetMgtMsgLog(FILLP_INT enable); 102 103#ifdef __cplusplus 104} 105#endif 106#endif /* FILLP_LOG_H */ 107 108