2022-09-05 14:13:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
enum class LogLevel
|
|
|
|
{
|
2022-09-08 15:02:40 +00:00
|
|
|
DEBUG,
|
2022-09-05 14:13:51 +00:00
|
|
|
INFO,
|
|
|
|
WARN,
|
|
|
|
ERROR
|
|
|
|
};
|
|
|
|
|
2022-10-01 13:35:11 +00:00
|
|
|
enum class Backend
|
|
|
|
{
|
|
|
|
Serial,
|
|
|
|
Console
|
|
|
|
};
|
|
|
|
|
2022-09-07 13:02:23 +00:00
|
|
|
#define PRINTF_LIKE(n, m) __attribute__((format(printf, n, m)))
|
|
|
|
|
2022-09-05 14:13:51 +00:00
|
|
|
namespace KernelLog
|
|
|
|
{
|
2022-09-07 13:02:23 +00: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);
|
2022-09-15 16:42:38 +00:00
|
|
|
void toggle_log_level(LogLevel level);
|
2022-10-01 13:35:11 +00:00
|
|
|
void toggle_log_backend(Backend backend);
|
2022-09-05 14:13:51 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 13:02:23 +00: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 14:13:51 +00:00
|
|
|
|
2022-09-08 15:02:40 +00:00
|
|
|
#define kdbg(...) kcommonlog(log, LogLevel::DEBUG, __VA_ARGS__)
|
|
|
|
#define kdbgln(...) kcommonlog(logln, LogLevel::DEBUG, __VA_ARGS__)
|
2022-09-07 13:02:23 +00: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__)
|