Marcin Niestroj | a418ad4 | 2022-06-14 19:17:28 +0200 | [diff] [blame] | 1 | /* |
| 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> |
| 9 | LOG_MODULE_REGISTER(mbedtls, CONFIG_MBEDTLS_LOG_LEVEL); |
| 10 | |
| 11 | #include "zephyr_mbedtls_priv.h" |
| 12 | |
| 13 | void zephyr_mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str) |
| 14 | { |
Marcin Niestroj | e4c11fd | 2022-06-15 12:39:17 +0200 | [diff] [blame] | 15 | const char *p, *basename = file; |
Marcin Niestroj | a418ad4 | 2022-06-14 19:17:28 +0200 | [diff] [blame] | 16 | |
| 17 | ARG_UNUSED(ctx); |
| 18 | |
| 19 | if (!file || !str) { |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | /* Extract basename from file */ |
Marcin Niestroj | e4c11fd | 2022-06-15 12:39:17 +0200 | [diff] [blame] | 24 | 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 Niestroj | a418ad4 | 2022-06-14 19:17:28 +0200 | [diff] [blame] | 29 | } |
| 30 | } |
| 31 | |
Marcin Niestroj | af37c09 | 2022-06-15 00:32:24 +0200 | [diff] [blame^] | 32 | 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 Niestroj | a418ad4 | 2022-06-14 19:17:28 +0200 | [diff] [blame] | 47 | } |