!110 优化hdf log处理方案

Merge pull request !110 from Zhang/master
This commit is contained in:
openharmony_ci 2021-09-11 10:03:18 +00:00 committed by Gitee
commit 0587a088b9
3 changed files with 82 additions and 6 deletions

View File

@ -27,16 +27,26 @@ extern "C" {
#define _HDF_FMT_TAG(TAG, LEVEL) "[" #LEVEL "/" #TAG "] "
#define HDF_FMT_TAG(TAG, LEVEL) _HDF_FMT_TAG(TAG, LEVEL)
#define HDF_LOG_BUF_SIZE 256
#define HDF_LOGV_WRAPPER(fmt, args...) printk(KERN_DEBUG HDF_FMT_TAG(HDF_LOG_TAG, V) fmt "\r\n", ## args)
bool deal_format(const char *fmt, char *str, size_t size);
#define HDF_LOGD_WRAPPER(fmt, args...) printk(KERN_DEBUG HDF_FMT_TAG(HDF_LOG_TAG, D) fmt "\r\n", ## args)
#define HDF_LOG_WRAPPER(fmt, args...) \
do { \
char tmp_fmt[HDF_LOG_BUF_SIZE] = {0}; \
if (deal_format(fmt, tmp_fmt, sizeof(tmp_fmt))) \
printk(tmp_fmt, ##args); \
} while (0)
#define HDF_LOGI_WRAPPER(fmt, args...) printk(KERN_INFO HDF_FMT_TAG(HDF_LOG_TAG, I) fmt "\r\n", ## args)
#define HDF_LOGV_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_DEBUG HDF_FMT_TAG(HDF_LOG_TAG, V) fmt "\r\n", ## args)
#define HDF_LOGW_WRAPPER(fmt, args...) printk(KERN_WARNING HDF_FMT_TAG(HDF_LOG_TAG, W) fmt "\r\n", ## args)
#define HDF_LOGD_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_DEBUG HDF_FMT_TAG(HDF_LOG_TAG, D) fmt "\r\n", ## args)
#define HDF_LOGE_WRAPPER(fmt, args...) printk(KERN_ERR HDF_FMT_TAG(HDF_LOG_TAG, E) fmt "\r\n", ## args)
#define HDF_LOGI_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_INFO HDF_FMT_TAG(HDF_LOG_TAG, I) fmt "\r\n", ## args)
#define HDF_LOGW_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_WARNING HDF_FMT_TAG(HDF_LOG_TAG, W) fmt "\r\n", ## args)
#define HDF_LOGE_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_ERR HDF_FMT_TAG(HDF_LOG_TAG, E) fmt "\r\n", ## args)
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -13,7 +13,7 @@
#
obj-y += osal_workqueue.o osal_thread.o osal_firmware.o osal_irq.o osal_mem.o osal_mutex.o osal_sem.o osal_spinlock.o \
osal_time.o osal_file.o osal_timer.o osal_cdev.o
osal_time.o osal_file.o osal_timer.o osal_cdev.o osal_deal_log_format.o
ccflags-y += -Iinclude/hdf \
-Iinclude/hdf/osal \
-Iinclude/hdf/utils \

66
osal/src/osal_deal_log_format.c Executable file
View File

@ -0,0 +1,66 @@
/*
* osal_deal_log_format.c
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/printk.h>
#include "securec.h"
#define NUMBER 2
static const char *g_property[NUMBER] = {"%{private}", "%{public}"};
static size_t g_property_len[NUMBER] = {10, 9};
bool deal_format(const char *fmt, char *dest, size_t size)
{
const char *ptr = fmt;
const char *ptr_cur = ptr;
errno_t ret;
size_t index = 0;
size_t i;
if (fmt == NULL || dest == NULL || size == 0) {
printk("%s invalid para", __func__);
return false;
}
while (ptr_cur != NULL && *ptr_cur != '\0') {
if (*ptr_cur == '%') {
for (i = 0; i < NUMBER; i++) {
if (strncmp(ptr_cur, g_property[i], g_property_len[i]) == 0) {
ret = strncpy_s(&dest[index], size - index, ptr, ptr_cur - ptr + 1);
if (ret != EOK) {
printk("%s strncpy_s error %d", __func__, ret);
return false;
}
index += (ptr_cur - ptr + 1);
ptr = ptr_cur + g_property_len[i];
ptr_cur = ptr;
break;
}
}
if (i == NUMBER)
ptr_cur++;
} else {
ptr_cur++;
}
}
ret = strcat_s(&dest[index], size - index, ptr);
if (ret != EOK) {
printk("%s strcat_s error %d", __func__, ret);
return false;
}
return true;
}