From 04978d7abe02e7f7e9092a44bb4d0ac3ec6ad366 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Tue, 4 Feb 2025 17:32:40 -0700 Subject: libmisc: log.h: Allow using n_* in headers without LOG_NAME --- libmisc/include/libmisc/log.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'libmisc') diff --git a/libmisc/include/libmisc/log.h b/libmisc/include/libmisc/log.h index 121b0e1..79c0ab6 100644 --- a/libmisc/include/libmisc/log.h +++ b/libmisc/include/libmisc/log.h @@ -1,6 +1,6 @@ /* libmisc/log.h - stdio logging * - * Copyright (C) 2024 Luke T. Shumaker + * Copyright (C) 2024-2025 Luke T. Shumaker * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -12,25 +12,23 @@ #include #include -#ifndef LOG_NAME - #error "each compilation unit that includes must define LOG_NAME" -#endif - #ifdef NDEBUG #define _LOG_NDEBUG 1 #else #define _LOG_NDEBUG 0 #endif +const char *const_byte_str(uint8_t b); + #define n_errorf(nam, fmt, ...) do { __lm_printf("error: " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) #define n_infof(nam, fmt, ...) do { __lm_printf("info : " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) #define n_debugf(nam, fmt, ...) do { if (LM_CAT3_(CONFIG_, nam, _DEBUG) && !_LOG_NDEBUG) \ __lm_printf("debug: " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) +#endif /* _LIBMISC_LOG_H_ */ + +#if defined(LOG_NAME) && !defined(errorf) #define errorf(fmt, ...) n_errorf(LOG_NAME, fmt, __VA_ARGS__) #define infof(fmt, ...) n_infof(LOG_NAME, fmt, __VA_ARGS__) #define debugf(fmt, ...) n_debugf(LOG_NAME, fmt, __VA_ARGS__) - -const char *const_byte_str(uint8_t b); - -#endif /* _LIBMISC_LOG_H_ */ +#endif -- cgit v1.2.3-2-g168b