blob: 170400264af0fb41f470d6145fd0ebac6167813f [file] [log] [blame]
Marcin Niestroja418ad42022-06-14 19:17:28 +02001/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 * Copyright (c) 2022 Marcin Niestroj
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#include <zephyr/logging/log.h>
9LOG_MODULE_REGISTER(mbedtls, CONFIG_MBEDTLS_LOG_LEVEL);
10
11#include "zephyr_mbedtls_priv.h"
12
13void zephyr_mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str)
14{
Marcin Niestroje4c11fd2022-06-15 12:39:17 +020015 const char *p, *basename = file;
Marcin Niestroja418ad42022-06-14 19:17:28 +020016
17 ARG_UNUSED(ctx);
18
19 if (!file || !str) {
20 return;
21 }
22
23 /* Extract basename from file */
Marcin Niestroje4c11fd2022-06-15 12:39:17 +020024 if (IS_ENABLED(CONFIG_MBEDTLS_DEBUG_EXTRACT_BASENAME_AT_RUNTIME)) {
25 for (p = basename = file; *p != '\0'; p++) {
26 if (*p == '/' || *p == '\\') {
27 basename = p + 1;
28 }
Marcin Niestroja418ad42022-06-14 19:17:28 +020029 }
30 }
31
Marcin Niestrojaf37c092022-06-15 00:32:24 +020032 switch (level) {
33 case 0:
34 case 1:
35 LOG_ERR("%s:%04d: %s", basename, line, str);
36 break;
37 case 2:
38 LOG_WRN("%s:%04d: %s", basename, line, str);
39 break;
40 case 3:
41 LOG_INF("%s:%04d: %s", basename, line, str);
42 break;
43 default:
44 LOG_DBG("%s:%04d: %s", basename, line, str);
45 break;
46 }
Marcin Niestroja418ad42022-06-14 19:17:28 +020047}