• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 /* ****************************************************************************
20     1 头文件包含
21 **************************************************************************** */
22 #include "oam_ext_if.h"
23 #include "securec.h"
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif
29 #endif
30 
31 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
32 #define PRINT printk
33 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
34 #define PRINT dprintf
35 
36 hi_u32 oam_log_level_set(hi_u32 log_level)
37 {
38     if (log_level >= OAM_LOG_LEVEL_BUTT) {
39         return HI_FAIL;
40     }
41 
42     g_level_log = log_level;
43     PRINT("\r\nSet log level to %d\r\n", log_level);
44     return HI_SUCCESS;
45 }
46 #endif
47 
48 
49 static const char* g_log_tag[OAM_LOG_LEVEL_BUTT] = {
50     [OAM_LOG_LEVEL_ERROR]   = "E",
51     [OAM_LOG_LEVEL_WARNING] = "W",
52     [OAM_LOG_LEVEL_INFO]    = "I",
53     [OAM_LOG_LEVEL_DEBUG]   = "D",
54     [OAM_LOG_LEVEL_VERBOSE] = "V",
55 };
56 
oal_print_nlogs(const hi_char * pfile_name,const hi_char * pfuc_name,hi_u16 us_line_no,void * pfunc_addr,hi_u8 uc_vap_id,hi_u8 en_feature_id,hi_u8 clog_level,hi_u8 uc_param_cnt,hi_char * fmt,...)57 hi_void oal_print_nlogs(const hi_char *pfile_name, const hi_char *pfuc_name, hi_u16 us_line_no, void *pfunc_addr,
58     hi_u8 uc_vap_id, hi_u8 en_feature_id, hi_u8 clog_level, hi_u8 uc_param_cnt, hi_char *fmt, ...)
59 {
60     hi_char buffer[OAM_PRINT_FORMAT_LENGTH] = {0};
61     hi_s32 offset;
62     hi_s32 tmp;
63 
64     hi_unref_param(pfile_name);
65     hi_unref_param(pfuc_name);
66     hi_unref_param(pfunc_addr);
67     hi_unref_param(uc_vap_id);
68     hi_unref_param(en_feature_id);
69     hi_unref_param(uc_param_cnt);
70 
71 
72     if (clog_level > g_level_log || clog_level >= OAM_LOG_LEVEL_BUTT) {
73         return;
74     }
75     offset = snprintf_s(buffer, OAM_PRINT_FORMAT_LENGTH, OAM_PRINT_FORMAT_LENGTH - 1, "[%d][%s:%d]",
76         oal_get_curr_time_ms(), g_log_tag[clog_level], us_line_no);
77     if (offset == -1) {
78         return;
79     }
80     va_list args;
81     va_start(args, fmt);
82     tmp = vsprintf_s(buffer + offset, OAM_PRINT_FORMAT_LENGTH - offset - 1, fmt, args);
83     if (tmp == -1) {
84         va_end(args);
85         return;
86     }
87     va_end(args);
88 
89     offset = offset + tmp;
90     if (snprintf_s(buffer + offset,
91         OAM_PRINT_FORMAT_LENGTH - offset, OAM_PRINT_FORMAT_LENGTH - offset - 1, "\r\n") == -1) {
92         return;
93     }
94     PRINT(buffer);
95     return;
96 }
97 
98 #ifdef __cplusplus
99 #if __cplusplus
100 }
101 #endif
102 #endif