1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
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 #include <iot_log.h>
17 
18 static EnIotLogLevel gIoTLogLevel = EN_IOT_LOG_LEVEL_TRACE;
19 static const char *gIoTLogLevelNames[] = {
20     "TRACE",
21     "DEBUG",
22     "INFO ",
23     "WARN ",
24     "ERROR",
25     "FATAL"
26 };
27 
IoTLogLevelSet(EnIotLogLevel level)28 int IoTLogLevelSet(EnIotLogLevel level)
29 {
30     int ret = -1;
31     if (level < EN_IOT_LOG_LEVEL_MAX) {
32         gIoTLogLevel = level;
33         ret = 0;
34     }
35     return ret;
36 }
37 
IoTLogLevelGet(void)38 EnIotLogLevel IoTLogLevelGet(void)
39 {
40     return gIoTLogLevel;
41 }
42 
IoTLogLevelGetName(EnIotLogLevel logLevel)43 const char *IoTLogLevelGetName(EnIotLogLevel logLevel)
44 {
45     if (logLevel >= EN_IOT_LOG_LEVEL_MAX) {
46         return "NULL ";
47     } else {
48         return gIoTLogLevelNames[logLevel];
49     }
50 }