<commit_before>/*
 * Copyright (c) 2018 - 2020 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <kernel.h>
#include <stdarg.h>
#include <stdio.h>

#include <openthread/platform/logging.h>
#include "openthread-core-zephyr-config.h"

#define LOG_MODULE_NAME net_openthread
#define LOG_LEVEL LOG_LEVEL_DBG
#include <logging/log.h>
LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#include "platform-zephyr.h"

/* Convert OT log level to zephyr log level. */
static inline int log_translate(otLogLevel aLogLevel)
{
	switch (aLogLevel) {
	case OT_LOG_LEVEL_NONE:
	case OT_LOG_LEVEL_CRIT:
		return LOG_LEVEL_ERR;
	case OT_LOG_LEVEL_WARN:
		return LOG_LEVEL_WRN;
	case OT_LOG_LEVEL_NOTE:
	case OT_LOG_LEVEL_INFO:
		return LOG_LEVEL_INF;
	case OT_LOG_LEVEL_DEBG:
		return LOG_LEVEL_DBG;
	default:
		break;
	}

	return -1;
}

void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion,
	       const char *aFormat, ...)
{
	/*
	 * The following speed optimization have been used:
	 * - arguments are counted at compile time
	 * - for none arguments aFormat is not checked for %s
	 * - for up to three arguments program uses fast path
	 * - time consuming string formatting is posponed to idle time
	 * TODO : add support for ll (problem for 32 bit processors)
	 */


#ifdef OPENTHREAD_CONFIG_PLAT_LOG_MACRO_NAME__COUNT_ARGS
	/* The arguments number has been counted by macro at compile time,
	 * and the value has been passed in unused (now) aLogRegion.
	 * If LogRegion value from OT is needed, rewrite macro
	 * OPENTHREAD_CONFIG_PLAT_LOG_MACRO_NAME__COUNT_ARGS and use higher
	 * bits to pass args_num.
	 */
	uint32_t args_num = (uint32_t) aLogRegion;
#else
	ARG_UNUSED(aLogRegion);

	uint32_t args_num = log_count_args(aFormat);
#endif

	va_list param_list;
	int level = log_translate(aLogLevel);

	if (level < 0) {
		return;
	}

	va_start(param_list, aFormat);

	/* We assume, that OT has no access to strdup utility,
	 * and we are not obliged to check, if string has already
	 * been duplicated. So, to save time, in Z_LOG_VA macro calls
	 * we will use LOG_STRDUP_EXEC option.
	 */
	Z_LOG_VA(level, aFormat, param_list, args_num, LOG_STRDUP_EXEC);
	va_end(param_list);
}<commit_msg>net: openthread: blank `otPlatLog` when logging is disabled<commit_after>/*
 * Copyright (c) 2018 - 2020 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <kernel.h>
#include <stdarg.h>
#include <stdio.h>

#include <openthread/platform/logging.h>
#include "openthread-core-zephyr-config.h"

#define LOG_MODULE_NAME net_openthread
#define LOG_LEVEL LOG_LEVEL_DBG
#include <logging/log.h>
LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#include "platform-zephyr.h"

/* Convert OT log level to zephyr log level. */
static inline int log_translate(otLogLevel aLogLevel)
{
	switch (aLogLevel) {
	case OT_LOG_LEVEL_NONE:
	case OT_LOG_LEVEL_CRIT:
		return LOG_LEVEL_ERR;
	case OT_LOG_LEVEL_WARN:
		return LOG_LEVEL_WRN;
	case OT_LOG_LEVEL_NOTE:
	case OT_LOG_LEVEL_INFO:
		return LOG_LEVEL_INF;
	case OT_LOG_LEVEL_DEBG:
		return LOG_LEVEL_DBG;
	default:
		break;
	}

	return -1;
}

void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
{
	ARG_UNUSED(aLogRegion);

#if defined(CONFIG_LOG)
	int level = log_translate(aLogLevel);
	uint32_t args_num = log_count_args(aFormat);
	va_list param_list;

	if (level < 0) {
		return;
	}

	va_start(param_list, aFormat);

	/* We assume, that OT has no access to strdup utility,
	 * and we are not obliged to check, if string has already
	 * been duplicated. So, to save time, in Z_LOG_VA macro calls
	 * we will use LOG_STRDUP_EXEC option.
	 */
	Z_LOG_VA(level, aFormat, param_list, args_num, LOG_STRDUP_EXEC);
	va_end(param_list);
#else
	ARG_UNUSED(aLogLevel);
	ARG_UNUSED(aFormat);
#endif

}
{'fraction_non_alphanumeric': 0.0896351136964569, 'fraction_numerical': 0.008989952406134321, 'mean_word_length': 4.637853949329359, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1779674', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1359, 'n_words': 379}