UEFIStarter
a simple UEFI framework
Macros | Functions | Variables
logger.c File Reference

Logging facility, supports verbosity levels. More...

#include <Library/UefiLib.h>
#include <Library/MemoryAllocationLib.h>
#include <UEFIStarter/core/logger.h>

Macros

#define LOGGER_FORWARD_FUNC(NAME, LEVEL)
 helper macro for quickly defining a callable logging function More...
 

Functions

LOGLEVEL get_log_level ()
 Fetches the current log level. More...
 
LOGLEVEL set_log_level (LOGLEVEL level)
 Sets a new log level. More...
 
void log_print (LOGLEVEL level, CHAR16 *msg)
 Default log writer: prints to text console. More...
 
static void _logger_function_va (LOGLEVEL level, UINT16 *message, VA_LIST args)
 internal: formats log message and calls log writer with final string to log. More...
 
static void EFIAPI _trace (CHAR16 *fmt,...)
 internal: forwards TRACE messages to internal handler More...
 
static void EFIAPI _debug (CHAR16 *fmt,...)
 internal: forwards DEBUG messages to internal handler More...
 
static void EFIAPI _info (CHAR16 *fmt,...)
 internal: forwards INFO messages to internal handler More...
 
static void EFIAPI _warn (CHAR16 *fmt,...)
 internal: forwards WARN messages to internal handler More...
 
static void EFIAPI _error (CHAR16 *fmt,...)
 internal: forwards ERROR messages to internal handler More...
 
void reset_logger_entry_counts ()
 Resets all log levels' message counts. More...
 
UINTN get_logger_entry_count (LOGLEVEL level)
 Gets a log level's message count. More...
 
void kill ()
 Immediately halts the UEFI environment. More...
 
logger_print_function_tset_logger_function (logger_print_function_t *func)
 Sets a new log writer. More...
 

Variables

const CHAR16 * logger_level_names [] ={L"",L"ERROR",L"WARN",L"INFO",L"DEBUG",L"TRACE"}
 list of log level's printable names
 
static int logging_threshold =TRACE
 current log level; anything higher that won't be logged
 
static UINTN logger_entry_counts [TRACE+1]
 numbers of logged messages for each log level
 
logger_print_function_tlogger_print_func =log_print
 pointer to the current log writer
 
const loggers_t LOG
 The global logging facility. More...
 

Detailed Description

Logging facility, supports verbosity levels.

Author
Richard Nusser
License
GPLv3 (see http://www.gnu.org/licenses/)
See also
https://github.com/rinusser/UEFIStarter

Macro Definition Documentation

◆ LOGGER_FORWARD_FUNC

#define LOGGER_FORWARD_FUNC (   NAME,
  LEVEL 
)
Value:
static void EFIAPI NAME(CHAR16 *fmt, ...) \
{ \
VA_LIST args; \
VA_START(args,fmt); \
_logger_function_va(LEVEL,fmt,args); \
VA_END(args); \
}
cmdline_argument_t args[]
list of command-line arguments
Definition: rotation.c:30

helper macro for quickly defining a callable logging function

Parameters
NAMEthe logging function's name
LEVELthe log level to log at

Function Documentation

◆ get_log_level()

LOGLEVEL get_log_level ( )

Fetches the current log level.

Returns
the current log level

◆ set_log_level()

LOGLEVEL set_log_level ( LOGLEVEL  level)

Sets a new log level.

You can disable logging by calling this with log level "OFF".

Parameters
levelthe new log level to use
Returns
the previous log level

◆ log_print()

void log_print ( LOGLEVEL  level,
CHAR16 *  msg 
)

Default log writer: prints to text console.

Parameters
levelthe log level to log at
msgthe log message, as UTF-16

◆ _logger_function_va()

static void _logger_function_va ( LOGLEVEL  level,
UINT16 *  message,
VA_LIST  args 
)
static

internal: formats log message and calls log writer with final string to log.

This function uses the same format strings as the Print() functions.

Parameters
levelthe log level to log at
messagethe message's format string
argsthe vararg list of parameters matching matching the format string's placeholder

◆ _trace()

static void EFIAPI _trace ( CHAR16 *  fmt,
  ... 
)
static

internal: forwards TRACE messages to internal handler

Parameters
fmtthe log entry's format string
...any additional parameters to be formatted

◆ _debug()

static void EFIAPI _debug ( CHAR16 *  fmt,
  ... 
)
static

internal: forwards DEBUG messages to internal handler

Parameters
fmtthe log entry's format string
...any additional parameters to be formatted

◆ _info()

static void EFIAPI _info ( CHAR16 *  fmt,
  ... 
)
static

internal: forwards INFO messages to internal handler

Parameters
fmtthe log entry's format string
...any additional parameters to be formatted

◆ _warn()

static void EFIAPI _warn ( CHAR16 *  fmt,
  ... 
)
static

internal: forwards WARN messages to internal handler

Parameters
fmtthe log entry's format string
...any additional parameters to be formatted

◆ _error()

static void EFIAPI _error ( CHAR16 *  fmt,
  ... 
)
static

internal: forwards ERROR messages to internal handler

Parameters
fmtthe log entry's format string
...any additional parameters to be formatted

◆ reset_logger_entry_counts()

void reset_logger_entry_counts ( )

Resets all log levels' message counts.

Used e.g. by the test framework to detect which tests generated errors.

◆ get_logger_entry_count()

UINTN get_logger_entry_count ( LOGLEVEL  level)

Gets a log level's message count.

Parameters
levelthe log level to get the count for
Returns
the number of logged messages at the given level since the last reset

◆ kill()

void kill ( )

Immediately halts the UEFI environment.

Use this to e.g. debug issues in graphical animations where it's vital to stop everything before the target gets painted over.

Technically the emitted interrupt 3 is usually used for debuggers but the UEFI specification requires INT 3 to be unassigned by default, thus halting everything. If you use this function with a debugger attached this will probably trigger the debugger instead.

◆ set_logger_function()

logger_print_function_t* set_logger_function ( logger_print_function_t func)

Sets a new log writer.

Use this to replace the built-in text mode writer, e.g. to output log messages in a graphical environment

Parameters
functhe new log writer function
Returns
the previous log writer function

Variable Documentation

◆ LOG

const loggers_t LOG
Initial value:
={
.trace=_trace,
.debug=_debug,
.info=_info,
.warn=_warn,
.error=_error
}
static void EFIAPI _error(CHAR16 *fmt,...)
internal: forwards ERROR messages to internal handler
Definition: logger.c:132
static void EFIAPI _warn(CHAR16 *fmt,...)
internal: forwards WARN messages to internal handler
Definition: logger.c:125
static void EFIAPI _trace(CHAR16 *fmt,...)
internal: forwards TRACE messages to internal handler
Definition: logger.c:104
static void EFIAPI _info(CHAR16 *fmt,...)
internal: forwards INFO messages to internal handler
Definition: logger.c:118
static void EFIAPI _debug(CHAR16 *fmt,...)
internal: forwards DEBUG messages to internal handler
Definition: logger.c:111

The global logging facility.

This contains function pointers for each log level, so users can call e.g. LOG.debug() to log a debug message.