40 lines
1.2 KiB
C
Raw Normal View History

2022-09-05 16:13:51 +02:00
#pragma once
enum class LogLevel
{
2022-09-08 17:02:40 +02:00
DEBUG,
2022-09-05 16:13:51 +02:00
INFO,
WARN,
ERROR
};
enum class Backend
{
Serial,
Console
};
2022-09-07 15:02:23 +02:00
#define PRINTF_LIKE(n, m) __attribute__((format(printf, n, m)))
2022-09-05 16:13:51 +02:00
namespace KernelLog
{
2022-09-07 15:02:23 +02:00
void log(const char* function, LogLevel level, const char* message, ...) PRINTF_LIKE(3, 4);
void logln(const char* function, LogLevel level, const char* message, ...) PRINTF_LIKE(3, 4);
void toggle_log_level(LogLevel level);
void toggle_log_backend(Backend backend);
2022-09-05 16:13:51 +02:00
}
2022-09-07 15:02:23 +02:00
#ifndef MODULE
#define kcommonlog(function, level, ...) KernelLog::function(__FUNCTION__, level, __VA_ARGS__)
#else
#define kcommonlog(function, level, ...) KernelLog::function(MODULE, level, __VA_ARGS__)
#endif
2022-09-05 16:13:51 +02:00
2022-09-08 17:02:40 +02:00
#define kdbg(...) kcommonlog(log, LogLevel::DEBUG, __VA_ARGS__)
#define kdbgln(...) kcommonlog(logln, LogLevel::DEBUG, __VA_ARGS__)
2022-09-07 15:02:23 +02:00
#define kinfo(...) kcommonlog(log, LogLevel::INFO, __VA_ARGS__)
#define kinfoln(...) kcommonlog(logln, LogLevel::INFO, __VA_ARGS__)
#define kwarn(...) kcommonlog(log, LogLevel::WARN, __VA_ARGS__)
#define kwarnln(...) kcommonlog(logln, LogLevel::WARN, __VA_ARGS__)
#define kerror(...) kcommonlog(log, LogLevel::ERROR, __VA_ARGS__)
#define kerrorln(...) kcommonlog(logln, LogLevel::ERROR, __VA_ARGS__)