diff --git a/examples/apps/cli/main.c b/examples/apps/cli/main.c index 2ede597cd..d13ed203c 100644 --- a/examples/apps/cli/main.c +++ b/examples/apps/cli/main.c @@ -38,7 +38,6 @@ #include #include #include -#include #include #include "openthread-system.h" @@ -163,14 +162,3 @@ pseudo_reset: return 0; } - -#if OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_APP -void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) -{ - va_list ap; - - va_start(ap, aFormat); - otCliPlatLogv(aLogLevel, aLogRegion, aFormat, ap); - va_end(ap); -} -#endif diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index 9c66e25c8..4c85a26da 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -44,6 +44,7 @@ set(COMMON_SOURCES cli_history.cpp cli_joiner.cpp cli_link_metrics.cpp + cli_logging.cpp cli_mac_filter.cpp cli_mdns.cpp cli_mesh_diag.cpp diff --git a/src/cli/cli_logging.cpp b/src/cli/cli_logging.cpp new file mode 100644 index 000000000..b788e454c --- /dev/null +++ b/src/cli/cli_logging.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2026, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file implements default logging functionality for CLI apps. + */ +#include "openthread-core-config.h" + +#include + +#include +#include + +#include "config/logging.h" + +#if OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_APP + +extern "C" OT_TOOL_WEAK void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) +{ + va_list ap; + + va_start(ap, aFormat); + otCliPlatLogv(aLogLevel, aLogRegion, aFormat, ap); + va_end(ap); +} + +#endif diff --git a/src/cli/radio.cmake b/src/cli/radio.cmake index 709a84ca8..75f610e00 100644 --- a/src/cli/radio.cmake +++ b/src/cli/radio.cmake @@ -46,6 +46,7 @@ target_include_directories(openthread-cli-radio PUBLIC ${OT_PUBLIC_INCLUDES} PRI target_sources(openthread-cli-radio PRIVATE cli.cpp + cli_logging.cpp cli_utils.cpp )