PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1#pragma once
2
3#include <sys/defs.h>
4
5#include <boot/boot_info.h>
6
7#include <stdarg.h>
8#include <stdbool.h>
9#include <stdint.h>
10#include <sys/fs.h>
11#include <sys/math.h>
12#include <sys/proc.h>
13
14/**
15 * @brief Kernel logging and debugging.
16 * @defgroup kernel_log Logging Subsystem
17 * @ingroup kernel
18 *
19 * @{
20 */
21
22/**
23 * @brief Maximum buffer size for various logging buffers.
24 */
25#define LOG_MAX_BUFFER 0x1000
26
27/**
28 * @brief Log levels.
29 */
39
40/**
41 * @brief Initialize the logging system.
42 */
43void log_init(void);
44
45/**
46 * @brief Expose kernel logs via the `/dev/klog` file.
47 */
48void log_expose(void);
49
50/**
51 * @brief Print a unformatted log message.
52 *
53 * @warning See `log_vprint()` regarding the log lock and `LOG_LEVEL_PANIC`.
54 *
55 * @param level The log level.
56 * @param string The message string.
57 * @param length The length of the message.
58 */
59void log_nprint(log_level_t level, const char* string, uint64_t length);
60
61/**
62 * @brief Print a formatted log message.
63 *
64 * @warning See `log_vprint()` regarding the log lock and `LOG_LEVEL_PANIC`.
65 *
66 * @param level The log level.
67 * @param format The format string.
68 * @param ... The format arguments.
69 */
70void log_print(log_level_t level, const char* format, ...);
71
72/**
73 * @brief Print a formatted log message with a va_list.
74 *
75 * @warning If the log level is `LOG_LEVEL_PANIC`, this function will not acquire the log lock to avoid recursive
76 * panics. Its up to the panic system to ensure all other CPUs are halted before calling this.
77 *
78 * @param level The log level.
79 * @param format The format string.
80 * @param args The va_list of arguments.
81 */
82void log_vprint(log_level_t level, const char* format, va_list args);
83
84#ifndef NDEBUG
85#define LOG_DEBUG(format, ...) log_print(LOG_LEVEL_DEBUG, format __VA_OPT__(, ) __VA_ARGS__)
86#else
87#define LOG_DEBUG(format, ...) ((void)0)
88#endif
89
90#define LOG_USER(format, ...) log_print(LOG_LEVEL_USER, format __VA_OPT__(, ) __VA_ARGS__)
91#define LOG_INFO(format, ...) log_print(LOG_LEVEL_INFO, format __VA_OPT__(, ) __VA_ARGS__)
92#define LOG_WARN(format, ...) log_print(LOG_LEVEL_WARN, format __VA_OPT__(, ) __VA_ARGS__)
93#define LOG_ERR(format, ...) log_print(LOG_LEVEL_ERR, format __VA_OPT__(, ) __VA_ARGS__)
94#define LOG_PANIC(format, ...) log_print(LOG_LEVEL_PANIC, format __VA_OPT__(, ) __VA_ARGS__)
95
96/** @} */
static char format[MAX_NAME]
Definition screen.c:17
void log_init(void)
Initialize the logging system.
Definition log.c:93
void log_print(log_level_t level, const char *format,...)
Print a formatted log message.
Definition log.c:212
log_level_t
Log levels.
Definition log.h:31
void log_nprint(log_level_t level, const char *string, uint64_t length)
Print a unformatted log message.
Definition log.c:194
void log_vprint(log_level_t level, const char *format, va_list args)
Print a formatted log message with a va_list.
Definition log.c:220
void log_expose(void)
Expose kernel logs via the /dev/klog file.
Definition log.c:112
@ LOG_LEVEL_ERR
Definition log.h:36
@ LOG_LEVEL_DEBUG
Definition log.h:32
@ LOG_LEVEL_USER
Definition log.h:33
@ LOG_LEVEL_WARN
Definition log.h:35
@ LOG_LEVEL_PANIC
Definition log.h:37
@ LOG_LEVEL_INFO
Definition log.h:34
__builtin_va_list va_list
Definition stdarg.h:11
__UINT64_TYPE__ uint64_t
Definition stdint.h:17