summaryrefslogtreecommitdiff
path: root/libmisc/include/libmisc/log.h
blob: e6dfb527f18e0430d318b511093d4eef03e1517b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* libmisc/log.h - stdio logging
 *
 * Copyright (C) 2024-2025  Luke T. Shumaker <lukeshu@lukeshu.com>
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

#ifndef _LIBMISC_LOG_H_
#define _LIBMISC_LOG_H_

#include <stdint.h> /* for uint8_t */

#include <libmisc/macro.h>
#include <libmisc/fmt.h>
#include <libmisc/_intercept.h>

#ifdef NDEBUG
	#define _LOG_NDEBUG 1
#else
	#define _LOG_NDEBUG 0
#endif

const char *const_byte_str(uint8_t b);

extern lo_interface fmt_dest _log_dest;

#define log_n_errorln(nam, ...) fmt_print(_log_dest, "error: " LM_STR_(nam) ": ", __VA_ARGS__, "\n")
#define log_n_infoln(nam, ...)  fmt_print(_log_dest, "info : " LM_STR_(nam) ": ", __VA_ARGS__, "\n")
#define log_n_debugln(nam, ...) do { if (LM_CAT3_(CONFIG_, nam, _DEBUG) && !_LOG_NDEBUG) \
                                         fmt_print(_log_dest, "debug: " LM_STR_(nam) ": ", __VA_ARGS__, "\n"); } while (0)

#endif /* _LIBMISC_LOG_H_ */

#if defined(LOG_NAME) && !defined(log_errorln)
#define log_errorln(...) log_n_errorln(LOG_NAME, __VA_ARGS__)
#define log_infoln(...)  log_n_infoln(LOG_NAME, __VA_ARGS__)
#define log_debugln(...) log_n_debugln(LOG_NAME, __VA_ARGS__)
#endif