• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * hdf_log_adapter.h
3  *
4  * osal driver
5  *
6  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
7  *
8  * This software is licensed under the terms of the GNU General Public
9  * License version 2, as published by the Free Software Foundation, and
10  * may be copied, distributed, and modified under those terms.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  */
18 
19 #ifndef HDF_LOG_ADAPTER_H
20 #define HDF_LOG_ADAPTER_H
21 
22 #include <linux/printk.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif /* __cplusplus */
27 
28 #define _HDF_FMT_TAG(TAG, LEVEL) "[" #LEVEL "/" #TAG "] "
29 #define HDF_FMT_TAG(TAG, LEVEL) _HDF_FMT_TAG(TAG, LEVEL)
30 #define HDF_LOG_BUF_SIZE 256
31 
32 bool deal_format(const char *fmt, char *str, size_t size);
33 
34 #define HDF_LOG_WRAPPER(fmt, args...) \
35 	do { \
36 		char tmp_fmt[HDF_LOG_BUF_SIZE] = {0}; \
37 		if (deal_format(fmt, tmp_fmt, sizeof(tmp_fmt))) \
38 			printk(tmp_fmt, ##args); \
39 	} while (0)
40 
41 #define HDF_LOGV_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_DEBUG HDF_FMT_TAG(HDF_LOG_TAG, V) fmt "\r\n", ## args)
42 
43 #define HDF_LOGD_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_DEBUG HDF_FMT_TAG(HDF_LOG_TAG, D) fmt "\r\n", ## args)
44 
45 #define HDF_LOGI_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_INFO HDF_FMT_TAG(HDF_LOG_TAG, I) fmt "\r\n", ## args)
46 
47 #define HDF_LOGW_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_WARNING HDF_FMT_TAG(HDF_LOG_TAG, W) fmt "\r\n", ## args)
48 
49 #define HDF_LOGE_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_ERR HDF_FMT_TAG(HDF_LOG_TAG, E) fmt "\r\n", ## args)
50 #ifdef __cplusplus
51 }
52 #endif /* __cplusplus */
53 
54 #endif /* HDF_LOG_ADAPTER_H */
55 
56