From da6f225026543f20c9cf4c301f3ff7bee7c71a64 Mon Sep 17 00:00:00 2001 From: Kshitij Sisodia Date: Wed, 9 Jul 2025 11:16:24 +0100 Subject: [PATCH] MLECO-6389: Updates to logging interface Changes made to logging interface library. * Ability to disable logging using CMake configuration parameter `MLEK_LOG_ENABLE` * Changing the name of the CMake library target from `log` to `mlek_log` to avoid any potential conflict with any other third party libraries. Change-Id: If39cff5b5c3db5bedc10f1222160972e96605a69 Tested-by: mlecosys Reviewed-by: Alex Tawse Signed-off-by: Kshitij Sisodia --- CMakeLists.txt | 1 - MlekModule.cmake | 4 +- docs/sections/building.md | 10 ++- docs/sections/customizing.md | 2 +- scripts/cmake/cmsis-pack-gen/CMakeLists.txt | 5 +- .../configuration_options/common_opts.cmake | 19 ++--- .../configuration_options/options-preset.json | 22 +++--- scripts/cmake/executorch.cmake | 6 +- source/application/api/common/CMakeLists.txt | 2 +- .../api/fwk/executorch/CMakeLists.txt | 2 +- .../application/api/fwk/tflm/CMakeLists.txt | 2 +- source/hal/CMakeLists.txt | 2 +- .../source/components/audio/CMakeLists.txt | 4 +- .../audio/source/hal_audio_static_external.c | 3 +- .../source/components/camera/CMakeLists.txt | 6 +- .../camera/source/hal_camera_static.c | 5 +- .../source/hal_camera_static_external.c | 4 +- .../hal/source/components/lcd/CMakeLists.txt | 8 +- .../hal/source/components/npu/CMakeLists.txt | 6 +- .../source/components/npu_ta/CMakeLists.txt | 6 +- source/hal/source/hal.c | 4 +- .../hal/source/platform/mps3/CMakeLists.txt | 4 +- .../hal/source/platform/mps4/CMakeLists.txt | 4 +- .../hal/source/platform/native/CMakeLists.txt | 2 +- .../hal/source/platform/simple/CMakeLists.txt | 4 +- source/log/CMakeLists.txt | 47 ++++++++---- source/log/include/log_macros.h | 76 +++++++++++++------ source/math/CMakeLists.txt | 2 +- source/profiler/CMakeLists.txt | 5 +- 29 files changed, 163 insertions(+), 104 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1c05fe..28d5f32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,7 +200,6 @@ foreach(use_case ${USE_CASES}) "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}") target_link_libraries(${UC_LIB_NAME} PUBLIC - log arm_math hal profiler diff --git a/MlekModule.cmake b/MlekModule.cmake index 37f0843..370a47e 100644 --- a/MlekModule.cmake +++ b/MlekModule.cmake @@ -1,5 +1,5 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its +# SPDX-FileCopyrightText: Copyright 2024-2025 Arm Limited and/or its # affiliates # SPDX-License-Identifier: Apache-2.0 # @@ -68,7 +68,7 @@ set_platform_global_defaults() message(STATUS "Using CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}") # Make sure the following options are defined before proceeding. -assert_defined(LOG_LEVEL) +assert_defined(MLEK_LOG_LEVEL) assert_defined(TARGET_PLATFORM) assert_defined(USE_CASE_BUILD) assert_defined(CPU_PROFILE_ENABLED) diff --git a/docs/sections/building.md b/docs/sections/building.md index 4025d49..57e6dd2 100644 --- a/docs/sections/building.md +++ b/docs/sections/building.md @@ -270,9 +270,13 @@ The build parameters are: set to false, but can be turned on for FPGA targets. The FVP and the CPU core cycle counts are **not** meaningful and are not to be used. -- `LOG_LEVEL`: Sets the verbosity level for the output of the application over `UART`, or `stdout`. Valid values are: - `LOG_LEVEL_TRACE`, `LOG_LEVEL_DEBUG`, `LOG_LEVEL_INFO`, `LOG_LEVEL_WARN`, and `LOG_LEVEL_ERROR`. The default is set - to: `LOG_LEVEL_INFO`. +- `MLEK_LOG_ENABLE`: Enables/disables logging for the whole application. Default is set to `ON`, but if this + project is wrapped as a dependency, the definitions provided by logging interface could be overridden or disabled + altogether. + +- `MLEK_LOG_LEVEL`: Sets the verbosity level for the output of the application over `UART`, or `stdout`. Valid values + are: `MLEK_LOG_LEVEL_TRACE`, `MLEK_LOG_LEVEL_DEBUG`, `MLEK_LOG_LEVEL_INFO`, `MLEK_LOG_LEVEL_WARN`, and + `MLEK_LOG_LEVEL_ERROR`. The default is set to: `MLEK_LOG_LEVEL_INFO`. - `_MODEL_PATH`: The path to the model file that is processed and is included into the application `axf` file. The default value points to one of the delivered set of models. Make sure that the model chosen is aligned diff --git a/docs/sections/customizing.md b/docs/sections/customizing.md index 1d95993..2fa2464 100644 --- a/docs/sections/customizing.md +++ b/docs/sections/customizing.md @@ -535,7 +535,7 @@ However, for clarity, here is the full list of available functions: - `warn` - printf wrapper for warning messages. - `printf_err` - printf wrapper for error messages. -`printf` wrappers can be switched off with `LOG_LEVEL` define: +`printf` wrappers can be switched off with `MLEK_LOG_LEVEL` define: `trace (0) < debug (1) < info (2) < warn (3) < error (4)`. diff --git a/scripts/cmake/cmsis-pack-gen/CMakeLists.txt b/scripts/cmake/cmsis-pack-gen/CMakeLists.txt index 174089f..58d6916 100644 --- a/scripts/cmake/cmsis-pack-gen/CMakeLists.txt +++ b/scripts/cmake/cmsis-pack-gen/CMakeLists.txt @@ -1,5 +1,6 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates +# SPDX-FileCopyrightText: Copyright 2022, 2025 Arm Limited and/or +# its affiliates # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -39,7 +40,7 @@ if (NOT TARGET arm_math) add_subdirectory(${ARM_MATH_PROJECT_DIR} ${CMAKE_BINARY_DIR}/math) endif() -if (NOT TARGET log) +if (NOT TARGET mlek_log) add_subdirectory(${LOGGING_PROJECT_DIR} ${CMAKE_BINARY_DIR}/log) endif() diff --git a/scripts/cmake/configuration_options/common_opts.cmake b/scripts/cmake/configuration_options/common_opts.cmake index d4157d6..149f171 100644 --- a/scripts/cmake/configuration_options/common_opts.cmake +++ b/scripts/cmake/configuration_options/common_opts.cmake @@ -1,6 +1,6 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2021-2022, 2024 Arm Limited and/or its -# affiliates +# SPDX-FileCopyrightText: Copyright 2021-2022, 2024-2025 Arm Limited and/or +# its affiliates # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,16 +27,13 @@ message(STATUS "Assessing common user options...") include(util_functions) -USER_OPTION(LOG_LEVEL "Log level for the application" - LOG_LEVEL_INFO - STRING) +USER_OPTION(MLEK_LOG_ENABLE "Enable MLEK logging functions." + ON + BOOL) -set_property(CACHE LOG_LEVEL PROPERTY STRINGS - LOG_LEVEL_TRACE - LOG_LEVEL_DEBUG - LOG_LEVEL_INFO - LOG_LEVEL_WARN - LOG_LEVEL_ERROR) +USER_OPTION(MLEK_LOG_LEVEL "Log level for the application" + MLEK_LOG_LEVEL_INFO + STRING) USER_OPTION(ML_FRAMEWORK "Select the ML inference framework to be used." "TensorFlowLiteMicro" diff --git a/scripts/cmake/configuration_options/options-preset.json b/scripts/cmake/configuration_options/options-preset.json index 57b7a7d..e6401cd 100644 --- a/scripts/cmake/configuration_options/options-preset.json +++ b/scripts/cmake/configuration_options/options-preset.json @@ -10,9 +10,9 @@ "name": "log-trace", "hidden": true, "cacheVariables": { - "LOG_LEVEL": { + "MLEK_LOG_LEVEL": { "type": "STRING", - "value": "LOG_LEVEL_TRACE" + "value": "MLEK_LOG_LEVEL_TRACE" } } }, @@ -20,9 +20,9 @@ "name": "log-debug", "hidden": true, "cacheVariables": { - "LOG_LEVEL": { + "MLEK_LOG_LEVEL": { "type": "STRING", - "value": "LOG_LEVEL_DEBUG" + "value": "MLEK_LOG_LEVEL_DEBUG" } } }, @@ -30,9 +30,9 @@ "name": "log-info", "hidden": true, "cacheVariables": { - "LOG_LEVEL": { + "MLEK_LOG_LEVEL": { "type": "STRING", - "value": "LOG_LEVEL_INFO" + "value": "MLEK_LOG_LEVEL_INFO" } } }, @@ -40,9 +40,9 @@ "name": "log-warning", "hidden": true, "cacheVariables": { - "LOG_LEVEL": { + "MLEK_LOG_LEVEL": { "type": "STRING", - "value": "LOG_LEVEL_WARN" + "value": "MLEK_LOG_LEVEL_WARN" } } }, @@ -50,9 +50,9 @@ "name": "log-error", "hidden": true, "cacheVariables": { - "LOG_LEVEL": { + "MLEK_LOG_LEVEL": { "type": "STRING", - "value": "LOG_LEVEL_ERROR" + "value": "MLEK_LOG_LEVEL_ERROR" } } }, @@ -68,4 +68,4 @@ } } ] -} \ No newline at end of file +} diff --git a/scripts/cmake/executorch.cmake b/scripts/cmake/executorch.cmake index 23fd336..da8304e 100644 --- a/scripts/cmake/executorch.cmake +++ b/scripts/cmake/executorch.cmake @@ -62,10 +62,10 @@ endif() set(EXECUTORCH_PAL_DEFAULT minimal) # Map ExecuTorch supported log levels -if (${LOG_LEVEL} STREQUAL LOG_LEVEL_TRACE OR - ${LOG_LEVEL} STREQUAL LOG_LEVEL_DEBUG) +if (${LOG_LEVEL} STREQUAL MLEK_LOG_LEVEL_TRACE OR + ${LOG_LEVEL} STREQUAL MLEK_LOG_LEVEL_DEBUG) set(EXECUTORCH_LOG_LEVEL "Debug") -elseif(${LOG_LEVEL} STREQUAL LOG_LEVEL_INFO) +elseif(${LOG_LEVEL} STREQUAL MLEK_LOG_LEVEL_INFO) set(EXECUTORCH_LOG_LEVEL "Info") else() set(EXECUTORCH_LOG_LEVEL "Error") diff --git a/source/application/api/common/CMakeLists.txt b/source/application/api/common/CMakeLists.txt index 52b4010..2183822 100644 --- a/source/application/api/common/CMakeLists.txt +++ b/source/application/api/common/CMakeLists.txt @@ -46,7 +46,7 @@ target_sources(${COMMON_UC_UTILS_TARGET} PRIVATE # Link time library targets: target_link_libraries(${COMMON_UC_UTILS_TARGET} PUBLIC - log # Logging functions + mlek_log # Logging interface arm_math # Math functions ml-framework-iface) # ML framework interface diff --git a/source/application/api/fwk/executorch/CMakeLists.txt b/source/application/api/fwk/executorch/CMakeLists.txt index d49a353..eb8b626 100644 --- a/source/application/api/fwk/executorch/CMakeLists.txt +++ b/source/application/api/fwk/executorch/CMakeLists.txt @@ -47,7 +47,7 @@ target_include_directories(${ML_FWK_ET_TARGET} PUBLIC # Link time library targets: target_link_libraries(${ML_FWK_ET_TARGET} PUBLIC - log # Logging functions + mlek_log # Logging functions ml-framework-iface # ML framework interface lib ${MLEK_EXECUTORCH_LINK_STR}) # ExecuTorch libraries diff --git a/source/application/api/fwk/tflm/CMakeLists.txt b/source/application/api/fwk/tflm/CMakeLists.txt index 40f7e8c..8eba9cd 100644 --- a/source/application/api/fwk/tflm/CMakeLists.txt +++ b/source/application/api/fwk/tflm/CMakeLists.txt @@ -57,7 +57,7 @@ target_include_directories(${ML_FWK_TFLM_TARGET} PUBLIC # Link time library targets: target_link_libraries(${ML_FWK_TFLM_TARGET} PUBLIC - log # Logging functions + mlek_log # Logging functions ml-framework-iface # ML framework interface tensorflow-lite-micro) # TensorFlow Lite Micro library diff --git a/source/hal/CMakeLists.txt b/source/hal/CMakeLists.txt index 9079550..220dbeb 100644 --- a/source/hal/CMakeLists.txt +++ b/source/hal/CMakeLists.txt @@ -57,7 +57,7 @@ add_subdirectory(${PLATFORM_DRIVERS_DIR} ${CMAKE_BINARY_DIR}/platform_driver) # Link time library targets: target_link_libraries(${HAL_TARGET} PUBLIC - log # Logging functions + mlek_log # Logging functions lcd_iface # LCD interface platform_drivers # Platform drivers implementing the required interfaces ) diff --git a/source/hal/source/components/audio/CMakeLists.txt b/source/hal/source/components/audio/CMakeLists.txt index b664c45..dd7950d 100644 --- a/source/hal/source/components/audio/CMakeLists.txt +++ b/source/hal/source/components/audio/CMakeLists.txt @@ -1,5 +1,5 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or +# SPDX-FileCopyrightText: Copyright 2024-2025 Arm Limited and/or # its affiliates # SPDX-License-Identifier: Apache-2.0 # @@ -34,7 +34,7 @@ target_sources(hal_audio_static_streams PRIVATE source/hal_audio_static.c source/hal_audio_static_external.c) target_include_directories(hal_audio_static_streams PRIVATE source) -target_link_libraries(hal_audio_static_streams PUBLIC hal_audio_interface log) +target_link_libraries(hal_audio_static_streams PUBLIC hal_audio_interface mlek_log) target_compile_definitions(hal_audio_static_streams PRIVATE $<$:HAL_AUDIO_LOOP>) diff --git a/source/hal/source/components/audio/source/hal_audio_static_external.c b/source/hal/source/components/audio/source/hal_audio_static_external.c index c761d3f..db9d3a6 100644 --- a/source/hal/source/components/audio/source/hal_audio_static_external.c +++ b/source/hal/source/components/audio/source/hal_audio_static_external.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its + * SPDX-FileCopyrightText: Copyright 2024-2025 Arm Limited and/or its * affiliates * SPDX-License-Identifier: Apache-2.0 * @@ -17,6 +17,7 @@ */ #include "log_macros.h" #include "hal_audio_static_external.h" +#include /** These functions must be provided to this interface */ __attribute__((weak)) const char* get_sample_data_filename(uint32_t idx) diff --git a/source/hal/source/components/camera/CMakeLists.txt b/source/hal/source/components/camera/CMakeLists.txt index b10ac7c..fdb5af6 100644 --- a/source/hal/source/components/camera/CMakeLists.txt +++ b/source/hal/source/components/camera/CMakeLists.txt @@ -1,5 +1,5 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or +# SPDX-FileCopyrightText: Copyright 2024-2025 Arm Limited and/or # its affiliates # SPDX-License-Identifier: Apache-2.0 # @@ -34,7 +34,7 @@ target_sources(hal_camera_static_images PRIVATE source/hal_camera_static.c source/hal_camera_static_external.c) target_include_directories(hal_camera_static_images PRIVATE source) -target_link_libraries(hal_camera_static_images PUBLIC hal_camera_interface log) +target_link_libraries(hal_camera_static_images PUBLIC hal_camera_interface mlek_log) target_compile_definitions(hal_camera_static_images PRIVATE $<$:HAL_CAMERA_LOOP>) @@ -50,7 +50,7 @@ if (${FVP_VSI_ENABLED}) add_library(hal_camera_vsi STATIC EXCLUDE_FROM_ALL source/hal_camera_vsi.c) target_link_libraries(hal_camera_vsi PUBLIC hal_camera_interface - log + mlek_log virtual_streaming_interface) target_compile_definitions(hal_camera_vsi PRIVATE DYNAMIC_IFM_BASE=${DYNAMIC_IFM_BASE} diff --git a/source/hal/source/components/camera/source/hal_camera_static.c b/source/hal/source/components/camera/source/hal_camera_static.c index f10978e..df8d9b2 100644 --- a/source/hal/source/components/camera/source/hal_camera_static.c +++ b/source/hal/source/components/camera/source/hal_camera_static.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its + * SPDX-FileCopyrightText: Copyright 2024-2025 Arm Limited and/or its * affiliates * SPDX-License-Identifier: Apache-2.0 * @@ -18,8 +18,9 @@ #include "hal_camera.h" #include "log_macros.h" #include "hal_camera_static_external.h" - +#include #include +#include typedef struct hal_camera_device_ { char name[32]; diff --git a/source/hal/source/components/camera/source/hal_camera_static_external.c b/source/hal/source/components/camera/source/hal_camera_static_external.c index b75b83f..b03d45b 100644 --- a/source/hal/source/components/camera/source/hal_camera_static_external.c +++ b/source/hal/source/components/camera/source/hal_camera_static_external.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its + * SPDX-FileCopyrightText: Copyright 2024-2025 Arm Limited and/or its * affiliates * SPDX-License-Identifier: Apache-2.0 * @@ -16,6 +16,8 @@ * limitations under the License. */ #include "log_macros.h" +#include +#include __attribute__((weak)) const char* get_sample_data_filename(uint32_t idx) { diff --git a/source/hal/source/components/lcd/CMakeLists.txt b/source/hal/source/components/lcd/CMakeLists.txt index 6d0aec5..d87c4d9 100644 --- a/source/hal/source/components/lcd/CMakeLists.txt +++ b/source/hal/source/components/lcd/CMakeLists.txt @@ -1,5 +1,5 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2022, 2024 Arm Limited and/or +# SPDX-FileCopyrightText: Copyright 2022, 2024-2025 Arm Limited and/or # its affiliates # SPDX-License-Identifier: Apache-2.0 # @@ -60,7 +60,7 @@ target_compile_definitions(${LCD_MPS3_COMPONENT_TARGET} $<$:LCD_TITLE_STRING=\"${LCD_TITLE_STRING}\">) ## Logging utilities: -if (NOT TARGET log) +if (NOT TARGET mlek_log) if (NOT DEFINED LOG_PROJECT_DIR) message(FATAL_ERROR "LOG_PROJECT_DIR needs to be defined.") endif() @@ -70,7 +70,7 @@ endif() ## Add dependencies target_link_libraries(${LCD_MPS3_COMPONENT_TARGET} PUBLIC ${LCD_IFACE_TARGET} - log) + mlek_log) # Display status message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) @@ -96,7 +96,7 @@ target_sources(${LCD_STUBS_COMPONENT_TARGET} ## Add dependencies target_link_libraries(${LCD_STUBS_COMPONENT_TARGET} PUBLIC ${LCD_IFACE_TARGET} - log) + mlek_log) # Display status message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/source/hal/source/components/npu/CMakeLists.txt b/source/hal/source/components/npu/CMakeLists.txt index 6671ed7..3fd768f 100644 --- a/source/hal/source/components/npu/CMakeLists.txt +++ b/source/hal/source/components/npu/CMakeLists.txt @@ -1,5 +1,5 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2022, 2024 Arm Limited and/or its +# SPDX-FileCopyrightText: Copyright 2022, 2024-2025 Arm Limited and/or its # affiliates # SPDX-License-Identifier: Apache-2.0 # @@ -88,7 +88,7 @@ endif () add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver) ## Logging utilities: -if (NOT TARGET log) +if (NOT TARGET mlek_log) if (NOT DEFINED LOG_PROJECT_DIR) message(FATAL_ERROR "LOG_PROJECT_DIR needs to be defined.") endif() @@ -174,7 +174,7 @@ target_sources(${ETHOS_U_NPU_COMPONENT} ## Add dependencies: target_link_libraries(${ETHOS_U_NPU_COMPONENT} PUBLIC ethosu_core_driver - log) + mlek_log) ## If the rte_components target has been defined, include it as a dependency here. This component ## gives access to certain CPU related functions and definitions that should come from the CMSIS diff --git a/source/hal/source/components/npu_ta/CMakeLists.txt b/source/hal/source/components/npu_ta/CMakeLists.txt index 2030849..7c70f7f 100644 --- a/source/hal/source/components/npu_ta/CMakeLists.txt +++ b/source/hal/source/components/npu_ta/CMakeLists.txt @@ -1,5 +1,5 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2022, 2024 Arm Limited and/or its +# SPDX-FileCopyrightText: Copyright 2022, 2024-2025 Arm Limited and/or its # affiliates # SPDX-License-Identifier: Apache-2.0 # @@ -56,7 +56,7 @@ endif() add_subdirectory(${ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH} ${CMAKE_BINARY_DIR}/timing_adapter) ## Logging utilities: -if (NOT TARGET log) +if (NOT TARGET mlek_log) if (NOT DEFINED LOG_PROJECT_DIR) message(FATAL_ERROR "LOG_PROJECT_DIR needs to be defined.") endif() @@ -85,7 +85,7 @@ target_compile_definitions(${ETHOS_U_NPU_TA_COMPONENT} ## Add dependencies target_link_libraries(${ETHOS_U_NPU_TA_COMPONENT} PUBLIC timing_adapter - log) + mlek_log) # Display status message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/source/hal/source/hal.c b/source/hal/source/hal.c index 4a5d88f..f2f4df9 100644 --- a/source/hal/source/hal.c +++ b/source/hal/source/hal.c @@ -1,5 +1,6 @@ /* - * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates + * SPDX-FileCopyrightText: Copyright 2022, 2025 Arm Limited and/or + * its affiliates * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,6 +19,7 @@ #include "platform_drivers.h" /* Platform drivers */ #include "log_macros.h" /* Logging macros */ +#include bool hal_platform_init(void) { diff --git a/source/hal/source/platform/mps3/CMakeLists.txt b/source/hal/source/platform/mps3/CMakeLists.txt index 900ce93..c895bee 100644 --- a/source/hal/source/platform/mps3/CMakeLists.txt +++ b/source/hal/source/platform/mps3/CMakeLists.txt @@ -136,7 +136,7 @@ target_include_directories(cmsis_device PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/${TARGET_SUBSYSTEM}) ## Logging utilities: -if (NOT TARGET log) +if (NOT TARGET mlek_log) if (NOT DEFINED LOG_PROJECT_DIR) message(FATAL_ERROR "LOG_PROJECT_DIR needs to be defined.") endif() @@ -145,7 +145,7 @@ endif() # Add dependencies: target_link_libraries(${PLATFORM_DRIVERS_TARGET} PUBLIC - log + mlek_log cmsis_device platform_pmu lcd_mps3 diff --git a/source/hal/source/platform/mps4/CMakeLists.txt b/source/hal/source/platform/mps4/CMakeLists.txt index 7b671ba..6d527a0 100644 --- a/source/hal/source/platform/mps4/CMakeLists.txt +++ b/source/hal/source/platform/mps4/CMakeLists.txt @@ -114,7 +114,7 @@ target_include_directories(cmsis_device PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/${TARGET_SUBSYSTEM}) ## Logging utilities: -if (NOT TARGET log) +if (NOT TARGET mlek_log) if (NOT DEFINED LOG_PROJECT_DIR) message(FATAL_ERROR "LOG_PROJECT_DIR needs to be defined.") endif() @@ -123,7 +123,7 @@ endif() # Add dependencies: target_link_libraries(${PLATFORM_DRIVERS_TARGET} PUBLIC - log + mlek_log cmsis_device platform_pmu lcd_stubs diff --git a/source/hal/source/platform/native/CMakeLists.txt b/source/hal/source/platform/native/CMakeLists.txt index 66985ac..512fb49 100644 --- a/source/hal/source/platform/native/CMakeLists.txt +++ b/source/hal/source/platform/native/CMakeLists.txt @@ -70,7 +70,7 @@ add_subdirectory(${COMPONENTS_DIR}/audio ${CMAKE_BINARY_DIR}/audio) # Add dependencies: target_link_libraries(${PLATFORM_DRIVERS_TARGET} PUBLIC - log + mlek_log platform_pmu lcd_stubs hal_audio_static_streams diff --git a/source/hal/source/platform/simple/CMakeLists.txt b/source/hal/source/platform/simple/CMakeLists.txt index ca4bb22..83a328d 100644 --- a/source/hal/source/platform/simple/CMakeLists.txt +++ b/source/hal/source/platform/simple/CMakeLists.txt @@ -88,7 +88,7 @@ target_include_directories(cmsis_device PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/${TARGET_SUBSYSTEM}) ## Logging utilities: -if (NOT TARGET log) +if (NOT TARGET mlek_log) if (NOT DEFINED LOG_PROJECT_DIR) message(FATAL_ERROR "LOG_PROJECT_DIR needs to be defined.") endif() @@ -98,7 +98,7 @@ endif() # Add dependencies: target_link_libraries(${PLATFORM_DRIVERS_TARGET} PUBLIC cmsis_device - log + mlek_log platform_pmu lcd_stubs hal_audio_static_streams diff --git a/source/log/CMakeLists.txt b/source/log/CMakeLists.txt index c0478de..e5437b7 100644 --- a/source/log/CMakeLists.txt +++ b/source/log/CMakeLists.txt @@ -1,5 +1,6 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates +# SPDX-FileCopyrightText: Copyright 2022, 2025 Arm Limited and/or +# its affiliates # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,24 +21,42 @@ ####################################################### cmake_minimum_required(VERSION 3.21.0) -set(BSP_LOGGING_TARGET log) +set(MLEK_LOG_TARGET mlek_log) -project(${BSP_LOGGING_TARGET} +project(${MLEK_LOG_TARGET} DESCRIPTION "Generic logging formatting header-only interface lib." LANGUAGES C) -add_library(${BSP_LOGGING_TARGET} INTERFACE) +set(MLEK_LOG_ENABLE ON + CACHE BOOL "Enable MLEK logging functions. Set this to off to disable all logging.") -if (DEFINED LOG_LEVEL) - message(STATUS "Setting log level to ${LOG_LEVEL}") - target_compile_definitions(${BSP_LOGGING_TARGET} - INTERFACE - LOG_LEVEL=${LOG_LEVEL}) +set(MLEK_LOG_LEVEL MLEK_LOG_LEVEL_INFO + CACHE STRING "Log level.") + +set_property(CACHE MLEK_LOG_LEVEL PROPERTY STRINGS + MLEK_LOG_LEVEL_TRACE + MLEK_LOG_LEVEL_DEBUG + MLEK_LOG_LEVEL_INFO + MLEK_LOG_LEVEL_WARN + MLEK_LOG_LEVEL_ERROR) + +add_library(${MLEK_LOG_TARGET} INTERFACE) + +if (MLEK_LOG_ENABLE) + target_compile_definitions(${MLEK_LOG_TARGET} INTERFACE + MLEK_LOG_ENABLE) + if (DEFINED MLEK_LOG_LEVEL) + message(STATUS "Setting log level to ${MLEK_LOG_LEVEL}") + target_compile_definitions(${MLEK_LOG_TARGET} INTERFACE + MLEK_LOG_LEVEL=${MLEK_LOG_LEVEL}) + endif() +else() + message(STATUS "MLEK log is disabled") endif() -target_include_directories(${BSP_LOGGING_TARGET} INTERFACE include) +target_include_directories(${MLEK_LOG_TARGET} INTERFACE include) -message(STATUS "*******************************************************") -message(STATUS "Library : " ${BSP_LOGGING_TARGET}) -message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR}) -message(STATUS "*******************************************************") +message(STATUS "**************************************************") +message(STATUS "Library: " ${MLEK_LOG_TARGET}) +message(STATUS "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR}) +message(STATUS "**************************************************") diff --git a/source/log/include/log_macros.h b/source/log/include/log_macros.h index 6c115ab..8a75f76 100644 --- a/source/log/include/log_macros.h +++ b/source/log/include/log_macros.h @@ -1,6 +1,7 @@ /* - * SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates - * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: Copyright 2021, 2025 Arm Limited and/or + * its affiliates + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +15,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef ML_EMBEDDED_CORE_LOG_H -#define ML_EMBEDDED_CORE_LOG_H +#ifndef MLEK_BASIC_LOGGER_H +#define MLEK_BASIC_LOGGER_H + +#if !defined(UNUSED) +#define UNUSED(x) ((void)(x)) +#endif /* #if !defined(UNUSED) */ + +#if defined(MLEK_LOG_ENABLE) #ifdef __cplusplus extern "C" { @@ -24,29 +31,26 @@ extern "C" { #include #include -#define LOG_LEVEL_TRACE 0 -#define LOG_LEVEL_DEBUG 1 -#define LOG_LEVEL_INFO 2 -#define LOG_LEVEL_WARN 3 -#define LOG_LEVEL_ERROR 4 +#define MLEK_LOG_LEVEL_TRACE (0) +#define MLEK_LOG_LEVEL_DEBUG (1) +#define MLEK_LOG_LEVEL_INFO (2) +#define MLEK_LOG_LEVEL_WARN (3) +#define MLEK_LOG_LEVEL_ERROR (4) -#ifndef LOG_LEVEL -#define LOG_LEVEL LOG_LEVEL_INFO -#endif /*LOG_LEVEL*/ +#ifndef MLEK_LOG_LEVEL +#define MLEK_LOG_LEVEL MLEK_LOG_LEVEL_INFO +#endif /* MLEK_LOG_LEVEL */ -#if !defined(UNUSED) -#define UNUSED(x) ((void)(x)) -#endif /* #if !defined(UNUSED) */ -#if (LOG_LEVEL == LOG_LEVEL_TRACE) +#if (MLEK_LOG_LEVEL == MLEK_LOG_LEVEL_TRACE) #define trace(...) \ printf("TRACE - "); \ printf(__VA_ARGS__) #else #define trace(...) -#endif /* LOG_LEVEL == LOG_LEVEL_TRACE */ +#endif /* LOG_LEVEL == MLEK_LOG_LEVEL_TRACE */ -#if (LOG_LEVEL <= LOG_LEVEL_DEBUG) +#if (MLEK_LOG_LEVEL <= MLEK_LOG_LEVEL_DEBUG) #define debug(...) \ printf("DEBUG - "); \ printf(__VA_ARGS__) @@ -54,7 +58,7 @@ extern "C" { #define debug(...) #endif /* LOG_LEVEL > LOG_LEVEL_TRACE */ -#if (LOG_LEVEL <= LOG_LEVEL_INFO) +#if (MLEK_LOG_LEVEL <= MLEK_LOG_LEVEL_INFO) #define info(...) \ printf("INFO - "); \ printf(__VA_ARGS__) @@ -62,7 +66,7 @@ extern "C" { #define info(...) #endif /* LOG_LEVEL > LOG_LEVEL_DEBUG */ -#if (LOG_LEVEL <= LOG_LEVEL_WARN) +#if (MLEK_LOG_LEVEL <= MLEK_LOG_LEVEL_WARN) #define warn(...) \ printf("WARN - "); \ printf(__VA_ARGS__) @@ -70,7 +74,7 @@ extern "C" { #define warn(...) #endif /* LOG_LEVEL > LOG_LEVEL_INFO */ -#if (LOG_LEVEL <= LOG_LEVEL_ERROR) +#if (MLEK_LOG_LEVEL <= MLEK_LOG_LEVEL_ERROR) #define printf_err(...) \ printf("ERROR - "); \ printf(__VA_ARGS__) @@ -82,4 +86,32 @@ extern "C" { } #endif -#endif /* ML_EMBEDDED_CORE_LOG_H */ +#else /* defined(MLEK_LOG_ENABLE) */ + +/** + * Logging macros in this file will not be used. + * Provide stubs if the definitions have not been overridden externally. + */ +#if !defined(trace) + #define trace(...) +#endif + +#if !defined(debug) + #define debug(...) +#endif + +#if !defined(info) + #define info(...) +#endif + +#if !defined(warn) + #define warn(...) +#endif + +#if !defined(printf_err) + #define printf_err(...) +#endif + +#endif /* defined(MLEK_LOG_ENABLE) */ + +#endif /* MLEK_BASIC_LOGGER_H */ diff --git a/source/math/CMakeLists.txt b/source/math/CMakeLists.txt index 009389c..9d9d0ad 100644 --- a/source/math/CMakeLists.txt +++ b/source/math/CMakeLists.txt @@ -32,7 +32,7 @@ target_sources(arm_math target_include_directories(arm_math PUBLIC include) -target_link_libraries(arm_math PRIVATE log) +target_link_libraries(arm_math PRIVATE mlek_log) if (${CMAKE_CROSSCOMPILING}) include(cmsis-dsp) diff --git a/source/profiler/CMakeLists.txt b/source/profiler/CMakeLists.txt index 5c0a433..f537c62 100644 --- a/source/profiler/CMakeLists.txt +++ b/source/profiler/CMakeLists.txt @@ -1,5 +1,6 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates +# SPDX-FileCopyrightText: Copyright 2022, 2025 Arm Limited and/or its +# affiliates # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,7 +33,7 @@ target_sources(profiler target_include_directories(profiler PUBLIC include) # Profiling API depends on the logging interface and the HAL library. -target_link_libraries(profiler PRIVATE log hal) +target_link_libraries(profiler PRIVATE hal mlek_log) # Display status message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) -- GitLab