Library Design
September 13, 2025 ยท View on GitHub
This document outlines the design of the library and key concepts.
Overview
All logging is happening via ulog_log function. ulog, ulog_t, ulog_topic_* and ulog_* macros use ulog_log.
Logging Mechanism
ulog_loggenerate and eventulog_event. The event contains all the info about the loggin message - level, message, file, line, function, etc.- The event is passed to
output_handle_all(...)function. This function is responsible for iterating over all registered handlers and calling them with the event. - There are 2 main internal handlers and N user handlers:
output_stdout_handler(...)- it is responsible for printing the log message to the console.output_file_handler(...)- this handler is responsible for writing the log message to a file. To enable it user must useulog_output_add_file(...)function to register a file pointer.- User handlers are configurable via
ULOG_BUILD_EXTRA_OUTPUTSdefine andulog_output_add(...)function. User can register any number of handlers and they will be called in the order they were registered.
output_stdout_handler(...)andoutput_file_handler(...)will uselog_print_event(...)function to format the message and print it. The function logic is configurable via a set of defines.log_print_event(...)accepts aulog_eventand aprint_targetobjects. The target can be a stream or a buffer.- The actual printing is done via
vprint(...)andprint(...)functions accepting aprint_targetand a formatted string using a printf-like interface. It usesvsnprintf(...)andvfprintf(...)to print the message to the target.
The proces is shown in the diagram below:
Code organization
The code is organized into two files. The source file consists of sections. Each section might rely on functionality of a previous section. Sections are meant to be encapsulated and not to rely on each other or some shared data - if possible. See code.md for more details.