My Kernel v0.1.0
Collaboration diagram for Logger:

Macros

#define PANIC(...)
 Call the panic function with the appropriate parameters.
 
#define log_array_fmt(_arr, _len, _fmt)
 Print the content of an array. More...
 

Enumerations

enum  log_level { }
 The different available logging levels. More...
 

Functions

void log (enum log_level, const char *domain, const char *msg,...)
 Print a log message onto the terminal. More...
 
void panic (u32 esp, const char *msg,...) __attribute__((__noreturn__))
 Completely stop the kernel's execution. More...
 
void stack_trace (void)
 Print the callstack to the kernel's console.
 
void log_set_level (enum log_level)
 Change the maximum log level to display.
 
#define log_err(format, ...)    log(LOG_LEVEL_ERR, LOG_DOMAIN, format __VA_OPT__(, ) __VA_ARGS__)
 Print a log message to the kernel's console.
 
#define log_warn(format, ...)    log(LOG_LEVEL_WARN, LOG_DOMAIN, format __VA_OPT__(, ) __VA_ARGS__)
 Print a log message to the kernel's console.
 
#define log_info(format, ...)    log(LOG_LEVEL_INFO, LOG_DOMAIN, format __VA_OPT__(, ) __VA_ARGS__)
 Print a log message to the kernel's console.
 
#define log_dbg(format, ...)    log(LOG_LEVEL_DEBUG, LOG_DOMAIN, format __VA_OPT__(, ) __VA_ARGS__)
 Print a log message to the kernel's console.
 
#define log_variable(_var)    log(LOG_LEVEL_DEBUG, "variable", "%s=" FMT32, stringify(_var), _var)
 Print the content of a variable to the kernel's terminal. More...
 
#define log_variable_8(_var)    log(LOG_LEVEL_DEBUG, "variable", "%s=" FMT8, stringify(_var), _var)
 Print the content of a variable to the kernel's terminal. More...
 
#define log_variable_16(_var)    log(LOG_LEVEL_DEBUG, "variable", "%s=" FMT16, stringify(_var), _var)
 Print the content of a variable to the kernel's terminal. More...
 
#define log_variable_64(_var)    log(LOG_LEVEL_DEBUG, "variable", "%s=" FMT64, stringify(_var), _var)
 Print the content of a variable to the kernel's terminal. More...
 
#define log_variable_str(_var)    log(LOG_LEVEL_DEBUG, "variable", "%s=%s", stringify(_var), _var)
 Print the content of a variable to the kernel's terminal. More...
 
#define log_array(_arr, _len)   log_array_fmt(_arr, _len, FMT32)
 Print the content of an array. More...
 
#define log_array_8(_arr, _len)   log_array_fmt(_arr, _len, FMT8)
 Print the content of an array. More...
 
#define log_array_16(_arr, _len)   log_array_fmt(_arr, _len, FMT16)
 Print the content of an array. More...
 
#define log_array_64(_arr, _len)   log_array_fmt(_arr, _len, FMT64)
 Print the content of an array. More...
 
#define log_array_str(_arr, _len)   log_array_fmt(_arr, _len, "%s")
 Print the content of an array. More...
 

Detailed Description

Logger

Logger library for our kernel

Usage

When using the logger, one must specify a domain used as a prefix for the message. The domain name is specified by defining the LOG_DOMAIN macro. If this macro is not defined, no prefix will be prefixed to the message.

For example, when logging an error related to serial devices, the caller could include this header file as follows:

#define LOG_DOMAIN "serial"
#include <kernel/logger.h>
// Then call one of the provided log function
log_err("error message goes here");
#define log_err(format,...)
Print a log message to the kernel's console.
Definition: logger.h:132

Macro Definition Documentation

◆ log_array

#define log_array (   _arr,
  _len 
)    log_array_fmt(_arr, _len, FMT32)

There exists different version of this wrapper depending on the size of the types inside the array.

log_array_fmt

◆ log_array_16

#define log_array_16 (   _arr,
  _len 
)    log_array_fmt(_arr, _len, FMT16)

There exists different version of this wrapper depending on the size of the types inside the array.

log_array_fmt

◆ log_array_64

#define log_array_64 (   _arr,
  _len 
)    log_array_fmt(_arr, _len, FMT64)

There exists different version of this wrapper depending on the size of the types inside the array.

log_array_fmt

◆ log_array_8

#define log_array_8 (   _arr,
  _len 
)    log_array_fmt(_arr, _len, FMT8)

There exists different version of this wrapper depending on the size of the types inside the array.

log_array_fmt

◆ log_array_fmt

#define log_array_fmt (   _arr,
  _len,
  _fmt 
)
Value:
{ \
log_dbg(stringify(_arr)); \
printk("{ "); \
for (size_t i = 0; i < (_len); ++i) \
printk("" _fmt ", ", (_arr)[i]); \
printk("}\n"); \
}
#define stringify(_x)
Preprocess an expression into a raw string.
Definition: stringify.h:8
Parameters
_arrThe array to print
_lenThe number of elements inside the array
_fmtThe format to use for the elements (LOG_FMT_*)

◆ log_array_str

#define log_array_str (   _arr,
  _len 
)    log_array_fmt(_arr, _len, "%s")

There exists different version of this wrapper depending on the size of the types inside the array.

log_array_fmt

◆ log_variable

#define log_variable (   _var)     log(LOG_LEVEL_DEBUG, "variable", "%s=" FMT32, stringify(_var), _var)

The name of the variable will be prefixed to the message.

There exists different version of this macro, depending on the type (numeric or string), and bit size (for numerics) of the variable.

◆ log_variable_16

#define log_variable_16 (   _var)     log(LOG_LEVEL_DEBUG, "variable", "%s=" FMT16, stringify(_var), _var)

The name of the variable will be prefixed to the message.

There exists different version of this macro, depending on the type (numeric or string), and bit size (for numerics) of the variable.

◆ log_variable_64

#define log_variable_64 (   _var)     log(LOG_LEVEL_DEBUG, "variable", "%s=" FMT64, stringify(_var), _var)

The name of the variable will be prefixed to the message.

There exists different version of this macro, depending on the type (numeric or string), and bit size (for numerics) of the variable.

◆ log_variable_8

#define log_variable_8 (   _var)     log(LOG_LEVEL_DEBUG, "variable", "%s=" FMT8, stringify(_var), _var)

The name of the variable will be prefixed to the message.

There exists different version of this macro, depending on the type (numeric or string), and bit size (for numerics) of the variable.

◆ log_variable_str

#define log_variable_str (   _var)     log(LOG_LEVEL_DEBUG, "variable", "%s=%s", stringify(_var), _var)

The name of the variable will be prefixed to the message.

There exists different version of this macro, depending on the type (numeric or string), and bit size (for numerics) of the variable.

Enumeration Type Documentation

◆ log_level

enum log_level
Note
The lower a level numerical representation is the more important it is
Enumerator
LOG_LEVEL_WARN 

error messages

LOG_LEVEL_INFO 

warning messages

LOG_LEVEL_DEBUG 

standard messages

LOG_LEVEL_COUNT 

debug messages

Function Documentation

◆ log()

void log ( enum  log_level,
const char *  domain,
const char *  msg,
  ... 
)

All logging functions will prefix the message with the specified domain name. The latter will change color depending on the logging level.

Parameters
levelThe level of the log
domainUsed as a prefix to the error message.
msgThe actual message

◆ panic()

void panic ( u32  esp,
const char *  msg,
  ... 
)

This function writes a BOLD RED message to the screen, and completely halts the kernel's execution.

This should only be called in case of unrecoverable errors, or asserts that should never be false and would prevent the kernel from functioning as expected.

@info This function's implementation is arch-specific