MonkOS  v0.1
A simple 64-bit operating system (x86_64)
log.h
Go to the documentation of this file.
1 //============================================================================
2 /// @file log.c
3 /// @brief Kernel logging module.
4 //
5 // Copyright 2016 Brett Vickers.
6 // Use of this source code is governed by a BSD-style license
7 // that can be found in the MonkOS LICENSE file.
8 //============================================================================
9 
10 #pragma once
11 
12 #include <core.h>
13 #include <stdarg.h>
14 
15 //----------------------------------------------------------------------------
16 // @enum loglevel_t
17 /// @brief A log level indicates the importance of a logged message.
18 //----------------------------------------------------------------------------
19 typedef enum loglevel
20 {
21  LOG_CRIT, ///< Critical error, occurs just prior to crashing
22  LOG_ERR, ///< Serious error in software or hardware
23  LOG_WARNING, ///< Warning about a significant issue
24  LOG_INFO, ///< Informational message
25  LOG_DEBUG, ///< Used for kernel debugging
26  LOG_DEFAULT, ///< Default kernel logging level
27 } loglevel_t;
28 
29 //----------------------------------------------------------------------------
30 // @typedef log_callback
31 /// @brief Callback handler called when a message is logged.
32 /// @param[in] level The log level of the message.
33 /// @param[in] msg The null-terminated string containing the logged
34 /// message.
35 //----------------------------------------------------------------------------
36 typedef void (*log_callback)(loglevel_t level, const char *msg);
37 
38 //----------------------------------------------------------------------------
39 // @function log_addcallback
40 /// @brief Add a callback handler for log messages.
41 /// @param[in] maxlevel Issue callback for log calls up to and including
42 /// this log level.
43 /// @param[in] cb The callback function
44 //----------------------------------------------------------------------------
45 void
47 
48 //----------------------------------------------------------------------------
49 // @function log_removecallback
50 /// @brief Remove a callback handler for log messages.
51 /// @param[in] cb The callback function
52 //----------------------------------------------------------------------------
53 void
55 
56 //----------------------------------------------------------------------------
57 // @function log
58 /// @brief Log a message to the kernel log buffer.
59 /// @param[in] level The importance level of the logged message.
60 /// @param[in] str The null-terminated string to be printed.
61 //----------------------------------------------------------------------------
62 void
63 log(loglevel_t level, const char *str);
64 
65 //----------------------------------------------------------------------------
66 // @function logf
67 /// @brief Log a printf-formatted message to the kernel log buffer.
68 /// @param[in] level The importance level of the logged message.
69 /// @param[in] format The null-terminated format string used to format the
70 /// text to be printed.
71 /// @param[in] ... Variable arguments list to be initialized with
72 /// va_start.
73 //----------------------------------------------------------------------------
74 void
75 logf(loglevel_t level, const char *format, ...);
76 
77 //----------------------------------------------------------------------------
78 // @function logvf
79 /// @brief Log a printf-formatted string using a variable argument list.
80 /// @param[in] level The importance level of the logged message.
81 /// @param[in] format The null-terminated format string used to format the
82 /// text to be printed.
83 /// @param[in] args Variable arguments list to be initialized with
84 /// va_start.
85 //----------------------------------------------------------------------------
86 void
87 logvf(loglevel_t level, const char *format, va_list args);
Used for kernel debugging.
Definition: log.h:25
Warning about a significant issue.
Definition: log.h:23
void logvf(loglevel_t level, const char *format, va_list args)
Log a printf-formatted string using a variable argument list.
Definition: log.c:204
Core include file.
Informational message.
Definition: log.h:24
void log(loglevel_t level, const char *str)
Log a message to the kernel log buffer.
Definition: log.c:188
void logf(loglevel_t level, const char *format,...)
Log a printf-formatted message to the kernel log buffer.
Definition: log.c:195
void log_removecallback(log_callback cb)
Remove a callback handler for log messages.
Definition: log.c:176
Critical error, occurs just prior to crashing.
Definition: log.h:21
loglevel_t
A log level indicates the importance of a logged message.
Definition: log.h:19
void(* log_callback)(loglevel_t level, const char *msg)
Callback handler called when a message is logged.
Definition: log.h:36
Default kernel logging level.
Definition: log.h:26
Serious error in software or hardware.
Definition: log.h:22
void log_addcallback(loglevel_t maxlevel, log_callback cb)
Add a callback handler for log messages.
Definition: log.c:165