1 /* 2 * Copyright (c) 2018 - 2020 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/kernel.h> 8 #include <stdarg.h> 9 #include <stdio.h> 10 11 #include <openthread/platform/logging.h> 12 #include "openthread-core-zephyr-config.h" 13 14 #define LOG_MODULE_NAME net_openthread 15 #define LOG_LEVEL LOG_LEVEL_DBG 16 #include <zephyr/logging/log.h> 17 LOG_MODULE_REGISTER(LOG_MODULE_NAME); 18 19 #include "platform-zephyr.h" 20 21 /* Convert OT log level to zephyr log level. */ log_translate(otLogLevel aLogLevel)22static inline int log_translate(otLogLevel aLogLevel) 23 { 24 switch (aLogLevel) { 25 case OT_LOG_LEVEL_NONE: 26 case OT_LOG_LEVEL_CRIT: 27 return LOG_LEVEL_ERR; 28 case OT_LOG_LEVEL_WARN: 29 return LOG_LEVEL_WRN; 30 case OT_LOG_LEVEL_NOTE: 31 case OT_LOG_LEVEL_INFO: 32 return LOG_LEVEL_INF; 33 case OT_LOG_LEVEL_DEBG: 34 return LOG_LEVEL_DBG; 35 default: 36 break; 37 } 38 39 return -1; 40 } 41 otPlatLog(otLogLevel aLogLevel,otLogRegion aLogRegion,const char * aFormat,...)42void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) 43 { 44 ARG_UNUSED(aLogRegion); 45 46 #if defined(CONFIG_LOG) 47 int level = log_translate(aLogLevel); 48 va_list param_list; 49 50 if (level < 0) { 51 return; 52 } 53 54 va_start(param_list, aFormat); 55 log_generic(level, aFormat, param_list); 56 va_end(param_list); 57 #else 58 ARG_UNUSED(aLogLevel); 59 ARG_UNUSED(aFormat); 60 #endif 61 62 } 63