summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-02-04 17:32:40 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-02-04 18:33:50 -0700
commit04978d7abe02e7f7e9092a44bb4d0ac3ec6ad366 (patch)
treea65d92e6304a73b94b57d4a869bdaa7a009f7386
parenta7c299d825038237c63cca919aec6de6be69c4db (diff)
libmisc: log.h: Allow using n_* in headers without LOG_NAME
-rw-r--r--libmisc/include/libmisc/log.h16
1 files changed, 7 insertions, 9 deletions
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 <lukeshu@lukeshu.com>
+ * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
@@ -12,25 +12,23 @@
#include <libmisc/macro.h>
#include <libmisc/_intercept.h>
-#ifndef LOG_NAME
- #error "each compilation unit that includes <libmisc/log.h> 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