| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #pragma once |
| 4 | |
| 5 | #include "mos/syslog/debug.hpp" |
| 6 | #include "mos/syslog/syslog.hpp" |
| 7 | |
| 8 | #include <mos/mos_global.h> |
| 9 | #include <mos/types.hpp> |
| 10 | #include <stdarg.h> |
| 11 | |
| 12 | #ifndef pr_fmt |
| 13 | #define pr_fmt(fmt) fmt // default format string |
| 14 | #endif |
| 15 | |
| 16 | #define emit_syslog(level, feat, fmt, ...) do_syslog(LogLevel::level, __FILE_NAME__, __func__, __LINE__, &mos_debug_info.feat, fmt, ##__VA_ARGS__) |
| 17 | #define emit_syslog_nofeat(level, fmt, ...) do_syslog(LogLevel::level, __FILE_NAME__, __func__, __LINE__, NULL, fmt, ##__VA_ARGS__) |
| 18 | |
| 19 | #define lprintk_debug_wrapper(feat, level, fmt, ...) \ |
| 20 | do \ |
| 21 | { \ |
| 22 | if (mos_debug_enabled(feat)) \ |
| 23 | emit_syslog(level, feat, fmt, ##__VA_ARGS__); \ |
| 24 | } while (0) |
| 25 | |
| 26 | // clang-format off |
| 27 | #define pr_dinfo2(feat, fmt, ...) lprintk_debug_wrapper(feat, INFO2, pr_fmt(fmt), ##__VA_ARGS__) |
| 28 | #define pr_dinfo(feat, fmt, ...) lprintk_debug_wrapper(feat, INFO, pr_fmt(fmt), ##__VA_ARGS__) |
| 29 | #define pr_demph(feat, fmt, ...) lprintk_debug_wrapper(feat, EMPH, pr_fmt(fmt), ##__VA_ARGS__) |
| 30 | #define pr_dwarn(feat, fmt, ...) lprintk_debug_wrapper(feat, WARN, pr_fmt(fmt), ##__VA_ARGS__) |
| 31 | #define pr_demerg(feat, fmt, ...) lprintk_debug_wrapper(feat, EMERG, pr_fmt(fmt), ##__VA_ARGS__) |
| 32 | #define pr_dfatal(feat, fmt, ...) lprintk_debug_wrapper(feat, FATAL, pr_fmt(fmt), ##__VA_ARGS__) |
| 33 | #define pr_dcont(feat, fmt, ...) do { if (mos_debug_enabled(feat)) pr_cont(fmt, ##__VA_ARGS__); } while (0) |
| 34 | |
| 35 | #define pr_info(fmt, ...) emit_syslog_nofeat(INFO, pr_fmt(fmt), ##__VA_ARGS__) |
| 36 | #define pr_info2(fmt, ...) emit_syslog_nofeat(INFO2, pr_fmt(fmt), ##__VA_ARGS__) |
| 37 | #define pr_emph(fmt, ...) emit_syslog_nofeat(EMPH, pr_fmt(fmt), ##__VA_ARGS__) |
| 38 | #define pr_warn(fmt, ...) emit_syslog_nofeat(WARN, pr_fmt(fmt), ##__VA_ARGS__) |
| 39 | #define pr_emerg(fmt, ...) emit_syslog_nofeat(EMERG, pr_fmt(fmt), ##__VA_ARGS__) |
| 40 | #define pr_fatal(fmt, ...) emit_syslog_nofeat(FATAL, pr_fmt(fmt), ##__VA_ARGS__) |
| 41 | #define pr_cont(fmt, ...) emit_syslog_nofeat(UNSET, "" fmt, ##__VA_ARGS__) |
| 42 | // clang-format on |
| 43 | |
| 44 | void print_to_console(Console *con, LogLevel loglevel, const char *message, size_t len); |
| 45 | |
| 46 | void lvprintk(LogLevel loglevel, const char *fmt, va_list args); |
| 47 | __printf(1, 2) void printk(const char *format, ...); |
| 48 | __printf(2, 3) void lprintk(LogLevel loglevel, const char *format, ...); |
| 49 | |
| 50 | bool printk_unquiet(void); |
| 51 | void printk_set_quiet(bool quiet); |
| 52 | |