The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
klog.h File Reference
#include "common/stdint.h"

Go to the source code of this file.

Macros

#define KLOG_LEVEL   KLOG_LEVEL_DEBUG
 compile-time minimum level.
#define KLOG_DEBUG(...)
#define KLOG_INFO(...)
#define KLOG_WARN(...)
#define KLOG_ERROR(...)

Enumerations

enum  klog_level_t { KLOG_LEVEL_DEBUG = 0 , KLOG_LEVEL_INFO , KLOG_LEVEL_WARN , KLOG_LEVEL_ERROR }
 kernel logging: level-tagged diagnostics written to the serial port. More...

Functions

void klog_init (void)
 initialize the logging backend (brings up the serial port).
void klog_device_init (void)
 register /dev/kmsg: each line a program writes becomes an info line in the log (on the serial port).
void klog_set_echo (void(*putchar)(char c))
 also write every log line with this function (the console during boot), or stop with NULL.
void klog (klog_level_t level, const char *fmt,...) __attribute__((format(printf
 write a level-tagged, formatted log line to the serial port.

Macro Definition Documentation

◆ KLOG_LEVEL

#define KLOG_LEVEL   KLOG_LEVEL_DEBUG

compile-time minimum level.

messages below this are dropped at compile time. defaults to INFO in release (NDEBUG) and DEBUG otherwise. override by defining KLOG_LEVEL on the compiler command line.

◆ KLOG_DEBUG

#define KLOG_DEBUG ( ...)
Value:
klog(KLOG_LEVEL_DEBUG, __VA_ARGS__)
void klog(klog_level_t level, const char *fmt,...)
Definition klog.c:34
@ KLOG_LEVEL_DEBUG
Definition klog.h:22

◆ KLOG_INFO

#define KLOG_INFO ( ...)
Value:
klog(KLOG_LEVEL_INFO, __VA_ARGS__)
@ KLOG_LEVEL_INFO
Definition klog.h:23

◆ KLOG_WARN

#define KLOG_WARN ( ...)
Value:
klog(KLOG_LEVEL_WARN, __VA_ARGS__)
@ KLOG_LEVEL_WARN
Definition klog.h:24

◆ KLOG_ERROR

#define KLOG_ERROR ( ...)
Value:
klog(KLOG_LEVEL_ERROR, __VA_ARGS__)
@ KLOG_LEVEL_ERROR
Definition klog.h:25

Enumeration Type Documentation

◆ klog_level_t

kernel logging: level-tagged diagnostics written to the serial port.

klog output goes to COM1 (see drivers/serial), so it is visible headlessly under QEMU with -serial stdio and works before/without the VGA console.

use the level macros (KLOG_DEBUG/INFO/WARN/ERROR) rather than calling klog() directly. each expands to nothing when its level is below the compile-time KLOG_LEVEL threshold, so verbose logging costs zero in release builds. log severity levels, lowest to highest.

Enumerator
KLOG_LEVEL_DEBUG 
KLOG_LEVEL_INFO 
KLOG_LEVEL_WARN 
KLOG_LEVEL_ERROR 

Function Documentation

◆ klog_init()

void klog_init ( void )

initialize the logging backend (brings up the serial port).

call once, early in boot, before any KLOG_* macro is used.

◆ klog_device_init()

void klog_device_init ( void )

register /dev/kmsg: each line a program writes becomes an info line in the log (on the serial port).

call once the device registry is up.

◆ klog_set_echo()

void klog_set_echo ( void(* putchar )(char c))

also write every log line with this function (the console during boot), or stop with NULL.

◆ klog()

void klog ( klog_level_t level,
const char * fmt,
... )

write a level-tagged, formatted log line to the serial port.

appends a trailing newline. prefer the KLOG_* macros over this.

Parameters
levelseverity of the message.
fmtprintf-style format string.