1060ff233Sopenharmony_ci/* 2060ff233Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3060ff233Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4060ff233Sopenharmony_ci * you may not use this file except in compliance with the License. 5060ff233Sopenharmony_ci * You may obtain a copy of the License at 6060ff233Sopenharmony_ci * 7060ff233Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8060ff233Sopenharmony_ci * 9060ff233Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10060ff233Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11060ff233Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12060ff233Sopenharmony_ci * See the License for the specific language governing permissions and 13060ff233Sopenharmony_ci * limitations under the License. 14060ff233Sopenharmony_ci */ 15060ff233Sopenharmony_ci 16060ff233Sopenharmony_ci#ifndef FILLP_LOG_H 17060ff233Sopenharmony_ci#define FILLP_LOG_H 18060ff233Sopenharmony_ci 19060ff233Sopenharmony_ci#include "fillp_os.h" 20060ff233Sopenharmony_ci#include "opt.h" 21060ff233Sopenharmony_ci 22060ff233Sopenharmony_ci#ifdef __cplusplus 23060ff233Sopenharmony_ciextern "C" { 24060ff233Sopenharmony_ci#endif 25060ff233Sopenharmony_ci 26060ff233Sopenharmony_ci#ifdef FILLP_LINUX 27060ff233Sopenharmony_ci 28060ff233Sopenharmony_ci#ifdef PDT_UT 29060ff233Sopenharmony_ci 30060ff233Sopenharmony_ci/* for UT statement coverage */ 31060ff233Sopenharmony_ci#define FILLP_LOG_IN(_level, _type, _pre, fmt, ...) 32060ff233Sopenharmony_ci 33060ff233Sopenharmony_ci#else 34060ff233Sopenharmony_ci 35060ff233Sopenharmony_ci#if FILLP_LOG_WITH_TIME 36060ff233Sopenharmony_ci 37060ff233Sopenharmony_cistatic inline void FillpLogGetNowTime(struct timeval *tv, struct tm *nowTime) 38060ff233Sopenharmony_ci{ 39060ff233Sopenharmony_ci (void)gettimeofday(tv, FILLP_NULL_PTR); 40060ff233Sopenharmony_ci time_t sec = (time_t)tv->tv_sec; 41060ff233Sopenharmony_ci (void)localtime_r(&sec, nowTime); 42060ff233Sopenharmony_ci} 43060ff233Sopenharmony_ci 44060ff233Sopenharmony_ci#define FILLP_LM_LOG_OUTPUT(_type, _level, _pre, fmt, ...) do { \ 45060ff233Sopenharmony_ci struct timeval tv; \ 46060ff233Sopenharmony_ci struct tm nowTime; \ 47060ff233Sopenharmony_ci FillpLogGetNowTime(&tv, &nowTime); \ 48060ff233Sopenharmony_ci (*g_fillpLmGlobal.lmCallbackFn.debugCallbackFunc)(_type, _level, 0, \ 49060ff233Sopenharmony_ci "%02d%02d %02d:%02d:%02d.%06ld %s:[%d] : <%s>" fmt "\r\n", \ 50060ff233Sopenharmony_ci nowTime.tm_mon + 1, nowTime.tm_mday, nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec, \ 51060ff233Sopenharmony_ci (long)tv.tv_usec, __func__, __LINE__, _pre, ##__VA_ARGS__); \ 52060ff233Sopenharmony_ci } while (0) 53060ff233Sopenharmony_ci 54060ff233Sopenharmony_ci#else 55060ff233Sopenharmony_ci 56060ff233Sopenharmony_ci#define FILLP_LM_LOG_OUTPUT(_type, _level, _pre, fmt, ...) ((*g_fillpLmGlobal.lmCallbackFn.debugCallbackFunc)( \ 57060ff233Sopenharmony_ci _type, _level, 0, "%s:[%d] : <%s>" fmt "\r\n", __func__, __LINE__, _pre, ##__VA_ARGS__)) 58060ff233Sopenharmony_ci 59060ff233Sopenharmony_ci#endif /* FILLP_LOG_WITH_TIME */ 60060ff233Sopenharmony_ci 61060ff233Sopenharmony_ci#define FILLP_LOG_IN(_level, _type, _pre, fmt, ...) \ 62060ff233Sopenharmony_ci do { \ 63060ff233Sopenharmony_ci if ((_level) >= g_fillpLmGlobal.debugLevel && \ 64060ff233Sopenharmony_ci (g_fillpLmGlobal.lmCallbackFn.debugCallbackFunc != FILLP_NULL_PTR)) { \ 65060ff233Sopenharmony_ci FILLP_LM_LOG_OUTPUT(_type, _level, _pre, fmt, ##__VA_ARGS__); \ 66060ff233Sopenharmony_ci } \ 67060ff233Sopenharmony_ci } while (0) 68060ff233Sopenharmony_ci 69060ff233Sopenharmony_ci#endif 70060ff233Sopenharmony_ci 71060ff233Sopenharmony_ci#else 72060ff233Sopenharmony_ci 73060ff233Sopenharmony_ci#define FILLP_LOG_IN(_level, _type, _pre, fmt, ...) 74060ff233Sopenharmony_ci 75060ff233Sopenharmony_ci#endif /* FILLP_LINUX */ 76060ff233Sopenharmony_ci 77060ff233Sopenharmony_ci#define FILLP_LOGERR(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_ERROR, FILLP_DBG_LOG, "F-LOGERR", fmt, ##__VA_ARGS__) 78060ff233Sopenharmony_ci 79060ff233Sopenharmony_ci#define FILLP_LOGWAR(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_WARNING, FILLP_DBG_LOG, "F-LOGWAR", fmt, ##__VA_ARGS__) 80060ff233Sopenharmony_ci 81060ff233Sopenharmony_ci#define FILLP_LOGINF(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_INFO, FILLP_DBG_LOG, "F-LOGINF", fmt, ##__VA_ARGS__) 82060ff233Sopenharmony_ci 83060ff233Sopenharmony_ci#define FILLP_LOGDTL(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_DETAIL, FILLP_DBG_LOG, "F-LOGDTL", fmt, ##__VA_ARGS__) 84060ff233Sopenharmony_ci 85060ff233Sopenharmony_ci#define FILLP_LOGDBG(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_DEBUG, FILLP_DBG_LOG, "F-LOGDBG", fmt, ##__VA_ARGS__) 86060ff233Sopenharmony_ci 87060ff233Sopenharmony_ci#define FILLP_LOGBUTT(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_BUTT, FILLP_DBG_LOG, "F-LOGBUTT", fmt, ##__VA_ARGS__) 88060ff233Sopenharmony_ci 89060ff233Sopenharmony_ci#define FILLP_HELPBUTT(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_BUTT, FILLP_DBG_HELP, "F-HELPBUTT", fmt, ##__VA_ARGS__) 90060ff233Sopenharmony_ci 91060ff233Sopenharmony_ci#define FILLP_SHOWDATABUTT(fmt, ...) \ 92060ff233Sopenharmony_ci FILLP_LOG_IN(FILLP_DBG_LVL_BUTT, FILLP_DBG_SHOW_DATA, "F-SHOWDATABUTT", fmt, ##__VA_ARGS__) 93060ff233Sopenharmony_ci 94060ff233Sopenharmony_ci#define FILLP_SHOWLEVELBUTT(fmt, ...) \ 95060ff233Sopenharmony_ci FILLP_LOG_IN(FILLP_DBG_LVL_BUTT, FILLP_DBG_SHOW_LEVEL, "F-SHOWLEVELBUTT", fmt, ##__VA_ARGS__) 96060ff233Sopenharmony_ci 97060ff233Sopenharmony_ci#ifdef FILLP_MGT_MSG_LOG 98060ff233Sopenharmony_ci#define FILLP_LOGMGTMSG(fmt, ...) FILLP_LOG_IN(FILLP_DBG_LVL_INFO, FILLP_DBG_LOG, "F-LOGMGTMSG", fmt, ##__VA_ARGS__) 99060ff233Sopenharmony_ci#endif 100060ff233Sopenharmony_ci 101060ff233Sopenharmony_ciFILLP_INT FillpApiSetMgtMsgLog(FILLP_INT enable); 102060ff233Sopenharmony_ci 103060ff233Sopenharmony_ci#ifdef __cplusplus 104060ff233Sopenharmony_ci} 105060ff233Sopenharmony_ci#endif 106060ff233Sopenharmony_ci#endif /* FILLP_LOG_H */ 107060ff233Sopenharmony_ci 108