MonkOS  v0.1
A simple 64-bit operating system (x86_64)
log.c File Reference

Kernel logging module. More...

#include <libc/stdio.h>
#include <libc/string.h>
#include <kernel/debug/log.h>

Go to the source code of this file.

Data Structures

struct  record_t
 A log record represents a single logged event. More...
 
struct  callback_t
 Used for registering logging callback functions. More...
 
struct  context
 The log context describes the state of the log buffers. More...
 

Macros

#define RBUFSHIFT   10
 
#define RBUFSIZE   (1 << RBUFSHIFT)
 
#define RBUFMASK   (RBUFSIZE - 1)
 
#define MBUFSHIFT   16
 
#define MBUFSIZE   (1 << MBUFSHIFT)
 
#define MBUFMASK   (MBUFSIZE - 1)
 
#define MAX_CALLBACKS   8
 

Functions

static void evict_record ()
 
static void evict_msg (int chars)
 
static void evict_oldest_msg ()
 
static int add_msg (const char *str)
 
static void add_record (int offset, loglevel_t level, const char *str)
 
void log_addcallback (loglevel_t maxlevel, log_callback cb)
 Add a callback handler for log messages. More...
 
void log_removecallback (log_callback cb)
 Remove a callback handler for log messages. More...
 
void log (loglevel_t level, const char *str)
 Log a message to the kernel log buffer. More...
 
void logf (loglevel_t level, const char *format,...)
 Log a printf-formatted message to the kernel log buffer. More...
 
void logvf (loglevel_t level, const char *format, va_list args)
 Log a printf-formatted string using a variable argument list. More...
 

Variables

static struct context lc
 

Detailed Description

Kernel logging module.

Definition in file log.c.


Data Structure Documentation

struct record_t

A log record represents a single logged event.

Definition at line 28 of file log.c.

Data Fields
loglevel_t level
int moffset Offset of message in context::mbuf.
struct callback_t

Used for registering logging callback functions.

Definition at line 35 of file log.c.

Data Fields
loglevel_t maxlevel
log_callback cb
struct context

The log context describes the state of the log buffers.

There are two buffers: the record buffer and the message buffer. The record buffer is a circular queue that contains records describing the most recent 1024 log messages. The message buffer contains the text messages associated with each of the records in the log buffer.

Definition at line 46 of file log.c.

Data Fields
record_t rbuf[RBUFSIZE] Circular record buffer.
int rhead index of oldest record in rbuf
int rtail rbuf index of next record to write
int rbufsz number of records in rbuf
char mbuf[MBUFSIZE] Circular message text buffer.
int mhead index of oldest char in mbuf
int mtail mbuf index of next char to write
int mbufsz the number of characters in mbuf
callback_t callbacks[MAX_CALLBACKS]
int callbacks_size number of registrations

Macro Definition Documentation

#define RBUFSHIFT   10

Definition at line 15 of file log.c.

#define RBUFSIZE   (1 << RBUFSHIFT)

Definition at line 16 of file log.c.

Referenced by add_record().

#define RBUFMASK   (RBUFSIZE - 1)

Definition at line 17 of file log.c.

Referenced by add_record(), and evict_record().

#define MBUFSHIFT   16

Definition at line 20 of file log.c.

#define MBUFSIZE   (1 << MBUFSHIFT)

Definition at line 21 of file log.c.

Referenced by add_msg().

#define MBUFMASK   (MBUFSIZE - 1)

Definition at line 22 of file log.c.

Referenced by evict_msg(), and evict_oldest_msg().

#define MAX_CALLBACKS   8

Definition at line 25 of file log.c.

Referenced by log_addcallback().

Function Documentation

static void evict_record ( )
static

Definition at line 68 of file log.c.

Referenced by add_record(), and evict_msg().

static void evict_msg ( int  chars)
static

Definition at line 75 of file log.c.

Referenced by add_msg().

static void evict_oldest_msg ( )
static

Definition at line 100 of file log.c.

Referenced by add_record().

static int add_msg ( const char *  str)
static

Definition at line 112 of file log.c.

Referenced by log(), and logvf().

static void add_record ( int  offset,
loglevel_t  level,
const char *  str 
)
static

Definition at line 139 of file log.c.

Referenced by log(), and logvf().

void log_addcallback ( loglevel_t  maxlevel,
log_callback  cb 
)

Add a callback handler for log messages.

Parameters
[in]maxlevelIssue callback for log calls up to and including this log level.
[in]cbThe callback function

Definition at line 165 of file log.c.

void log_removecallback ( log_callback  cb)

Remove a callback handler for log messages.

Parameters
[in]cbThe callback function

Definition at line 176 of file log.c.

void log ( loglevel_t  level,
const char *  str 
)

Log a message to the kernel log buffer.

Parameters
[in]levelThe importance level of the logged message.
[in]strThe null-terminated string to be printed.

Definition at line 188 of file log.c.

void logf ( loglevel_t  level,
const char *  format,
  ... 
)

Log a printf-formatted message to the kernel log buffer.

Parameters
[in]levelThe importance level of the logged message.
[in]formatThe null-terminated format string used to format the text to be printed.
[in]...Variable arguments list to be initialized with va_start.

Definition at line 195 of file log.c.

Referenced by acpi_init(), read_rsdt(), and read_xsdt().

void logvf ( loglevel_t  level,
const char *  format,
va_list  args 
)

Log a printf-formatted string using a variable argument list.

Parameters
[in]levelThe importance level of the logged message.
[in]formatThe null-terminated format string used to format the text to be printed.
[in]argsVariable arguments list to be initialized with va_start.

Definition at line 204 of file log.c.

Referenced by logf().

Variable Documentation

struct context lc
static