From 0189cd2b334b2d88302d13d6003c50a642db0bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonny=20Sv=C3=A4rd?= Date: Wed, 11 Oct 2023 13:33:44 +0000 Subject: Add option to turn off logging completely MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new ETHOSU_LOG_ENABLE variable in the CMakeLists.txt to toggle logging completely off, or else by the desired severity level. Turning off the logging will also disable the LOG() macro. Change-Id: I313a97fb1569000ae22637734ef4a60eedc56f70 Signed-off-by: Jonny Svärd --- src/ethosu_log.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ethosu_log.h b/src/ethosu_log.h index 582b91d..13f7726 100644 --- a/src/ethosu_log.h +++ b/src/ethosu_log.h @@ -1,6 +1,5 @@ /* * SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates - * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may @@ -41,32 +40,43 @@ #define ETHOSU_LOG_SEVERITY ETHOSU_LOG_WARN #endif +// Logs enabled by default +#ifndef ETHOSU_LOG_ENABLE +#define ETHOSU_LOG_ENABLE 1 +#endif + +#if ETHOSU_LOG_ENABLE +#define LOG_COMMON(s, f, ...) (void)fprintf(s, f, ##__VA_ARGS__) +#else +#define LOG_COMMON(s, f, ...) +#endif + // Log formatting -#define LOG(f, ...) (void)fprintf(stdout, f, ##__VA_ARGS__) +#define LOG(f, ...) LOG_COMMON(stdout, f, ##__VA__ARGS__) #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_ERR #define LOG_ERR(f, ...) \ - (void)fprintf(stderr, "E: " f " (%s:%d)\n", ##__VA_ARGS__, strrchr("/" __FILE__, '/') + 1, __LINE__) + LOG_COMMON(stderr, "E: " f " (%s:%d)\n", ##__VA_ARGS__, strrchr("/" __FILE__, '/') + 1, __LINE__) #else #define LOG_ERR(f, ...) #endif #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_WARN -#define LOG_WARN(f, ...) (void)fprintf(stdout, "W: " f "\n", ##__VA_ARGS__) +#define LOG_WARN(f, ...) LOG_COMMON(stdout, "W: " f "\n", ##__VA_ARGS__) #else #define LOG_WARN(f, ...) #endif #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_INFO -#define LOG_INFO(f, ...) (void)fprintf(stdout, "I: " f "\n", ##__VA_ARGS__) +#define LOG_INFO(f, ...) LOG_COMMON(stdout, "I: " f "\n", ##__VA_ARGS__) #else #define LOG_INFO(f, ...) #endif #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_DEBUG -#define LOG_DEBUG(f, ...) (void)fprintf(stdout, "D: %s(): " f "\n", __FUNCTION__, ##__VA_ARGS__) +#define LOG_DEBUG(f, ...) LOG_COMMON(stdout, "D: %s(): " f "\n", __FUNCTION__, ##__VA_ARGS__) #else #define LOG_DEBUG(f, ...) #endif -#endif \ No newline at end of file +#endif -- cgit v1.2.1