16 #define RBUFSIZE (1 << RBUFSHIFT) // 1024 17 #define RBUFMASK (RBUFSIZE - 1) 21 #define MBUFSIZE (1 << MBUFSHIFT) // 64KiB 22 #define MBUFMASK (MBUFSIZE - 1) 25 #define MAX_CALLBACKS 8 35 typedef struct callback
79 for (
int i = 0; i < chars &&
lc.
mbufsz > 0; i++) {
117 int schars =
strlen(str) + 1;
159 if (level <= callback->maxlevel)
160 callback->
cb(level, str);
198 va_start(args, format);
199 logvf(level, format, args);
record_t rbuf[RBUFSIZE]
Circular record buffer.
String and memory operations.
int mtail
mbuf index of next char to write
Used for registering logging callback functions.
callback_t callbacks[MAX_CALLBACKS]
int vsnprintf(char *buf, size_t n, const char *format, va_list arg)
Compose a printf-formatted string into the target buffer using a variable argument list...
void log_removecallback(log_callback cb)
Remove a callback handler for log messages.
void logvf(loglevel_t level, const char *format, va_list args)
Log a printf-formatted string using a variable argument list.
static void evict_record()
void * memmove(void *dst, const void *src, size_t num)
Move bytes from one memory region to another, even if the regions overlap.
static void evict_oldest_msg()
size_t strlen(const char *str)
Return the length of a null-terminated string.
static int add_msg(const char *str)
static void evict_msg(int chars)
int mhead
index of oldest char in mbuf
int rbufsz
number of records in rbuf
char mbuf[MBUFSIZE]
Circular message text buffer.
void logf(loglevel_t level, const char *format,...)
Log a printf-formatted message to the kernel log buffer.
loglevel_t
A log level indicates the importance of a logged message.
void(* log_callback)(loglevel_t level, const char *msg)
Callback handler called when a message is logged.
int callbacks_size
number of registrations
int rtail
rbuf index of next record to write
int rhead
index of oldest record in rbuf
int mbufsz
the number of characters in mbuf
#define arrsize(x)
Return the number of elements in the C array.
The log context describes the state of the log buffers.
static void add_record(int offset, loglevel_t level, const char *str)
A log record represents a single logged event.
void log_addcallback(loglevel_t maxlevel, log_callback cb)
Add a callback handler for log messages.
void log(loglevel_t level, const char *str)
Log a message to the kernel log buffer.
int moffset
Offset of message in context::mbuf.
void * memcpy(void *dst, const void *src, size_t num)
Copy bytes from one memory region to another.