Soletta™ Framework
|
Modules | |
Colors | |
ANSI/VT100 colors as understood by most consoles and terminals. | |
Data Structures | |
struct | sol_log_domain |
Structure containing the attributes of the domain used for logging. More... | |
Macros | |
#define | SOL_CRI(fmt,...) SOL_LOG(SOL_LOG_LEVEL_CRITICAL, fmt, ## __VA_ARGS__) |
Logs a message with critical level. More... | |
#define | SOL_DBG(fmt,...) SOL_LOG(SOL_LOG_LEVEL_DEBUG, fmt, ## __VA_ARGS__) |
Logs a message with debug level. More... | |
#define | SOL_ERR(fmt,...) SOL_LOG(SOL_LOG_LEVEL_ERROR, fmt, ## __VA_ARGS__) |
Logs a message with error level. More... | |
#define | SOL_EXP_CHECK(exp,...) |
Safety-check macro to check the expression exp . More... | |
#define | SOL_EXP_CHECK_GOTO(exp, label) |
Similar to SOL_EXP_CHECK but jumping to label instead of returning. More... | |
#define | SOL_INF(fmt,...) SOL_LOG(SOL_LOG_LEVEL_INFO, fmt, ## __VA_ARGS__) |
Logs a message with informational level. More... | |
#define | SOL_INT_CHECK(var, exp,...) SOL_INT_CHECK_IMPL(var, exp, __VA_ARGS__) |
Safety-check macro to check if integer var against exp . More... | |
#define | SOL_INT_CHECK_ERRNO(var, exp, err,...) SOL_INT_CHECK_IMPL_ERRNO(var, exp, err, __VA_ARGS__) |
Safety-check macro to check if integer var against exp (and set errno ). More... | |
#define | SOL_INT_CHECK_GOTO(var, exp, label) SOL_INT_CHECK_GOTO_IMPL(var, exp, label) |
Similar to SOL_INT_CHECK but jumping to label instead of returning. More... | |
#define | SOL_INT_CHECK_GOTO_ERRNO(var, exp, err, label) SOL_INT_CHECK_GOTO_IMPL_ERRNO(var, exp, label) |
Similar to SOL_INT_CHECK but jumping to label instead of returning (and setting errno value). More... | |
#define | SOL_LOG(level, fmt,...) |
Logs to SOL_LOG_DOMAIN using the given level and format message. More... | |
#define | SOL_LOG_DOMAIN sol_log_global_domain |
Defines the default log domain that is used by SOL_LOG(), SOL_CRI(), SOL_ERR(), SOL_WRN(), SOL_INF() and SOL_DBG(). More... | |
#define | SOL_LOG_FILE "" |
Macro defining what to log for file entries. More... | |
#define | SOL_LOG_FUNCTION "" |
Macro defining what to log for function entries. More... | |
#define | SOL_LOG_LEVEL_INIT() |
Sets the global log level based on the SOL_LOG_LEVEL macro. More... | |
#define | SOL_LOG_LEVEL_MAXIMUM -1 |
Ensures a maximum log level. More... | |
#define | SOL_LOG_LEVEL_POSSIBLE(level) (0) |
Check if log level is possible. More... | |
#define | SOL_LOG_LEVELS_INIT() |
Sets the log level of the given log domains. More... | |
#define | SOL_NULL_CHECK(ptr,...) |
Convenience macro to check for NULL pointer. More... | |
#define | SOL_NULL_CHECK_ERRNO(ptr, err,...) |
Convenience macro to check for NULL pointer (and set errno ). More... | |
#define | SOL_NULL_CHECK_GOTO(ptr, label) |
Convenience macro to check for NULL pointer and jump to a given label. More... | |
#define | SOL_NULL_CHECK_MSG(ptr, ret, fmt,...) |
Similar to SOL_NULL_CHECK but allowing for a custom warning message. More... | |
#define | SOL_NULL_CHECK_MSG_GOTO(ptr, label, fmt,...) |
Similar to SOL_NULL_CHECK_GOTO but allowing for a custom warning message. More... | |
#define | SOL_WRN(fmt,...) SOL_LOG(SOL_LOG_LEVEL_WARNING, fmt, ## __VA_ARGS__) |
Logs a message with warning level. More... | |
Typedefs | |
typedef struct sol_log_domain | sol_log_domain |
Structure containing the attributes of the domain used for logging. More... | |
Enumerations | |
enum | sol_log_level { SOL_LOG_LEVEL_CRITICAL = 0, SOL_LOG_LEVEL_ERROR, SOL_LOG_LEVEL_WARNING, SOL_LOG_LEVEL_INFO, SOL_LOG_LEVEL_DEBUG } |
Available logging levels. More... | |
Functions | |
static void | sol_log_domain_init_level (struct sol_log_domain *domain) |
Initialize domain log level based on system configuration. More... | |
static uint8_t | sol_log_get_abort_level (void) |
Get the logging level that triggers the program to abort. More... | |
static uint8_t | sol_log_get_level (void) |
Get the maximum log level allowed. More... | |
static const char * | sol_log_get_level_color (uint8_t level) |
Get the color code used for the given logging level level . More... | |
static bool | sol_log_get_show_colors (void) |
Get if color output is enabled or not. More... | |
static bool | sol_log_get_show_file (void) |
Get if showing source file's name is enabled or not. More... | |
static bool | sol_log_get_show_function (void) |
Get if showing function's name is enabled or not. More... | |
static bool | sol_log_get_show_line (void) |
Get if showing the line number is enabled or not. More... | |
static void | sol_log_level_to_str (uint8_t level, char *buf, size_t buflen) |
Convenience function to convert the logging level to string. More... | |
static void | sol_log_print (const struct sol_log_domain *domain, uint8_t message_level, const char *file, const char *function, int line, const char *format,...) |
Print out a message in a given domain and level. More... | |
static void | sol_log_print_function_stderr (void *data, const struct sol_log_domain *domain, uint8_t message_level, const char *file, const char *function, int line, const char *format, va_list args) |
Standard logging function that send to standard error output. More... | |
static void | sol_log_set_abort_level (uint8_t level) |
Set the logging level that should trigger the program to abort. More... | |
static void | sol_log_set_level (uint8_t level) |
Set the global domain maximum level to level . More... | |
static void | sol_log_set_print_function (void(*print)(void *data, const struct sol_log_domain *domain, uint8_t message_level, const char *file, const char *function, int line, const char *format, va_list args), const void *data) |
Set the function to print out log messages. More... | |
static void | sol_log_set_show_colors (bool enabled) |
Enable/Disables the use of colors in logging messages. More... | |
static void | sol_log_set_show_file (bool enabled) |
Enable/Disables the output of source file's name in logging messages. More... | |
static void | sol_log_set_show_function (bool enabled) |
Enable/Disables the output of function's name containing the logging messages. More... | |
static void | sol_log_set_show_line (bool enabled) |
Enable/Disables the output of the line number in logging messages. More... | |
static void | sol_log_vprint (const struct sol_log_domain *domain, uint8_t message_level, const char *file, const char *function, int line, const char *format, va_list args) |
Similar to sol_log_print, but called with va_list instead of a variable number of arguments. More... | |
Variables | |
struct sol_log_domain * | sol_log_global_domain |
Global logging domain. More... | |
#define SOL_CRI | ( | fmt, | |
... | |||
) | SOL_LOG(SOL_LOG_LEVEL_CRITICAL, fmt, ## __VA_ARGS__) |
#define SOL_DBG | ( | fmt, | |
... | |||
) | SOL_LOG(SOL_LOG_LEVEL_DEBUG, fmt, ## __VA_ARGS__) |
Logs a message with debug
level.
Logs a debug message to the SOL_LOG_DOMAIN using the given format message, as well as using current source file, line and function.
Referenced by _sol_glib_integration_source_fd_handlers_adjust(), armed_cb(), on_error(), and sol_glib_integration().
#define SOL_ERR | ( | fmt, | |
... | |||
) | SOL_LOG(SOL_LOG_LEVEL_ERROR, fmt, ## __VA_ARGS__) |
Logs a message with error
level.
Logs an error message to the SOL_LOG_DOMAIN using the given format message, as well as using current source file, line and function.
Referenced by _inform_user(), main(), mavlink_connect_cb(), mission_reached_cb(), mode_changed_cb(), on_connect(), position_changed_cb(), and takeoff().
#define SOL_EXP_CHECK | ( | exp, | |
... | |||
) |
Safety-check macro to check the expression exp
.
This macro logs a warning message and returns if the expression exp
is true
.
exp | Safety-check expression |
... | Optional return value |
Referenced by my_stream_api_close(), and my_stream_api_feed().
#define SOL_EXP_CHECK_GOTO | ( | exp, | |
label | |||
) |
Similar to SOL_EXP_CHECK but jumping to label
instead of returning.
This macro logs a warning message and jumps to label
if the expression exp
is true
.
exp | Safety-check expression |
label | goto label |
#define SOL_INF | ( | fmt, | |
... | |||
) | SOL_LOG(SOL_LOG_LEVEL_INFO, fmt, ## __VA_ARGS__) |
Logs a message with informational
level.
Logs an informational message to the SOL_LOG_DOMAIN using the given format message, as well as using current source file, line and function.
Referenced by disable_observing(), enabled(), found_device(), light_method_put(), main(), mavlink_connect_cb(), notify_callback(), on_connect(), on_disconnect(), on_message(), print_attr(), publish_callback(), reply_cb(), try_reconnect(), and update_light().
#define SOL_INT_CHECK | ( | var, | |
exp, | |||
... | |||
) | SOL_INT_CHECK_IMPL(var, exp, __VA_ARGS__) |
Safety-check macro to check if integer var
against exp
.
This macro logs a warning message and returns if the integer var
satisfies the expression exp
.
var | Integer to be check |
exp | Safety-check expression |
... | Optional return value |
Referenced by _can_read(), enabled(), hrs_measurement_read(), light_resource_to_rep(), logic_process(), my_stream_api_feed(), on_connect(), put_fill_repr_map(), request_cb(), timeout_cb(), and writer_in_process().
#define SOL_INT_CHECK_ERRNO | ( | var, | |
exp, | |||
err, | |||
... | |||
) | SOL_INT_CHECK_IMPL_ERRNO(var, exp, err, __VA_ARGS__) |
Safety-check macro to check if integer var
against exp
(and set errno
).
This macro logs a warning message and returns if the integer var satisfies the expression exp
. Additionally, it sets the errno
variable to err.
var | Integer to be check |
exp | Safety-check expression |
err | errno value to set |
... | Optional return value |
#define SOL_INT_CHECK_GOTO | ( | var, | |
exp, | |||
label | |||
) | SOL_INT_CHECK_GOTO_IMPL(var, exp, label) |
Similar to SOL_INT_CHECK but jumping to label
instead of returning.
This macro logs a warning message and jumps to label
if the integer var
satisfies the expression exp
.
var | Integer to be check |
exp | Safety-check expression |
label | goto label |
Referenced by _sol_glib_integration_source_fd_handlers_adjust(), _sol_glib_integration_source_prepare(), disable_observing(), iio_gyroscope_reader_cb(), light_method_get(), light_method_put(), main(), print_attr(), sol_glib_integration(), startup_network(), update_light(), and user_handle_get().
#define SOL_INT_CHECK_GOTO_ERRNO | ( | var, | |
exp, | |||
err, | |||
label | |||
) | SOL_INT_CHECK_GOTO_IMPL_ERRNO(var, exp, label) |
Similar to SOL_INT_CHECK but jumping to label
instead of returning (and setting errno
value).
This macro logs a warning message and jumps to label
if the integer var
satisfies the expression exp
. Additionally, it sets the errno
variable to err.
var | Integer to be check |
exp | Safety-check expression |
err | errno value to set |
label | goto label |
#define SOL_LOG | ( | level, | |
fmt, | |||
... | |||
) |
Logs to SOL_LOG_DOMAIN using the given level and format message.
Also uses the current source file, line and function.
#define SOL_LOG_DOMAIN sol_log_global_domain |
#define SOL_LOG_FILE "" |
Macro defining what to log for file entries.
Set at build time. By default, it's set to FILE
, i.e. the file name of the log call entry will be part of the log (and thus take part in the final Soletta binary/image). One can disable that behavior, though, when it'll be set to NULL
(and no file name will take part in the log entries).
#define SOL_LOG_FUNCTION "" |
Macro defining what to log for function entries.
Set at build time. By default, it's set to PRETTY_FUNCTION
, i.e. the function name of the log call entry will be part of the log (and thus take part in the final Soletta binary/image). One can disable that behavior, though, when it'll be set to NULL
(and no function name will take part in the log entries).
#define SOL_LOG_LEVEL_INIT | ( | ) |
Sets the global log level based on the SOL_LOG_LEVEL macro.
Not to be used directly. Applications using SOL_MAIN_DEFAULT can be built passing -DSOL_LOG_LEVEL="level" on CFLAGS
, in which case this macro will initialize the global log level to the value the macro is defined to.
#define SOL_LOG_LEVEL_MAXIMUM -1 |
Ensures a maximum log level.
If defined, this level will be ensured before sol_log_print() is called by SOL_LOG(), SOL_CRI(), SOL_ERR(), SOL_WRN(), SOL_INF() and SOL_DBG(), which will avoid calling sol_log_print() at all and since it is comparing two constants the compiler will optimize out the block, effectively removing such code (and associated string) from the output binary.
One should check using SOL_LOG_LEVEL_POSSIBLE().
It only affects log levels in the library functions. If an application is using Soletta log system, it needs to be changed using application CFLAGS.
So to disable all log levels greater than warning on application build: CFLAGS += -DSOL_LOG_LEVEL_MAXIMUM=2
#define SOL_LOG_LEVEL_POSSIBLE | ( | level | ) | (0) |
Check if log level is possible.
If SOL_LOG_LEVEL_MAXIMUM is set, it should be less or equal to it, otherwise it is always impossible.
#define SOL_LOG_LEVELS_INIT | ( | ) |
Sets the log level of the given log domains.
Not to be used directly. Applications using SOL_MAIN_DEFAULT can be built passing -DSOL_LOG_LEVELS="domain:level,..." on CFLAGS
, in which case this macro will initialize each domain's log level to the values specified in the macro.
#define SOL_NULL_CHECK | ( | ptr, | |
... | |||
) |
Convenience macro to check for NULL
pointer.
This macro logs a warning message and returns if the pointer ptr
happens to be NULL
.
ptr | Pointer to check |
... | Optional return value |
Referenced by _sol_glib_integration_on_source_fd(), _sol_glib_integration_source_fd_handlers_adjust(), enabled(), found_device(), my_stream_api_close(), my_stream_api_feed(), my_stream_api_new(), on_message(), publish_callback(), request_cb(), sol_efivars_write_string(), sol_fs_write_string(), sol_glib_integration(), sol_memmap_write_string(), startup(), timeout_cb(), and update_light().
#define SOL_NULL_CHECK_ERRNO | ( | ptr, | |
err, | |||
... | |||
) |
Convenience macro to check for NULL
pointer (and set errno
).
This macro logs a warning message and returns if the pointer ptr happens to be NULL
. Additionally, it sets the errno
variable to err.
ptr | Pointer to check |
err | errno value to set |
... | Optional return value |
#define SOL_NULL_CHECK_GOTO | ( | ptr, | |
label | |||
) |
Convenience macro to check for NULL
pointer and jump to a given label.
This macro logs a warning message and jumps to label
if the pointer ptr
happens to be NULL
.
ptr | Pointer to check |
label | goto label |
... | Optional return value |
Referenced by _sol_glib_integration_source_fd_handlers_adjust(), _sol_glib_integration_source_prepare(), main(), my_stream_api_feed(), my_stream_api_new(), sol_efivars_write_string(), sol_fs_write_string(), sol_glib_integration(), sol_memmap_write_string(), and user_handle_get().
#define SOL_NULL_CHECK_MSG | ( | ptr, | |
ret, | |||
fmt, | |||
... | |||
) |
Similar to SOL_NULL_CHECK but allowing for a custom warning message.
ptr | Pointer to check |
ret | Value to return |
fmt | A standard 'printf()' format string |
... | The arguments for fmt |
#define SOL_NULL_CHECK_MSG_GOTO | ( | ptr, | |
label, | |||
fmt, | |||
... | |||
) |
Similar to SOL_NULL_CHECK_GOTO but allowing for a custom warning message.
ptr | Pointer to check |
label | goto label |
fmt | A standard 'printf()' format string |
... | The arguments for fmt |
#define SOL_WRN | ( | fmt, | |
... | |||
) | SOL_LOG(SOL_LOG_LEVEL_WARNING, fmt, ## __VA_ARGS__) |
Logs a message with warning
level.
Logs a warning message to the SOL_LOG_DOMAIN using the given format message, as well as using current source file, line and function.
Referenced by _can_read(), _can_write(), _sol_glib_integration_source_acquire(), found_resource(), got_get_response(), iio_gyroscope_reader_cb(), light_method_get(), light_method_put(), main(), on_connect(), publish_callback(), sol_glib_integration(), and startup().
typedef struct sol_log_domain sol_log_domain |
Structure containing the attributes of the domain used for logging.
enum sol_log_level |
|
inlinestatic |
Initialize domain log level based on system configuration.
The system configuration may be environment variables like $SOL_LOG_LEVEL=NUMBER
(or sol_log_set_level()) to apply for all or $SOL_LOG_LEVELS=<domain1_name>
:<domain1_level>,<domainN_name>:<domainN_level> to give each domain its specific level.
domain | the structure to fill level with system configuration value. |
|
inlinestatic |
Get the logging level that triggers the program to abort.
|
inlinestatic |
Get the maximum log level allowed.
|
inlinestatic |
Get the color code used for the given logging level level
.
level | Logging level |
|
inlinestatic |
Get if color output is enabled or not.
true
if enabled, false
otherwise
|
inlinestatic |
Get if showing source file's name is enabled or not.
true
if enabled, false
otherwise
|
inlinestatic |
Get if showing function's name is enabled or not.
true
if enabled, false
otherwise
|
inlinestatic |
Get if showing the line number is enabled or not.
true
if enabled, false
otherwise
|
inlinestatic |
Convenience function to convert the logging level
to string.
level | Logging level |
buf | Where to write the string |
buflen | Buffer size |
|
inlinestatic |
Print out a message in a given domain and level.
This function will print out the given message only if the given domain's level is greater or equal to the message_level. Then it will call the current print function as set by sol_log_set_print_function(), which defaults to sol_log_print_function_stderr().
Some environment variables affect the behavior:
$SOL_LOG_ABORT=LEVEL
if message_level is less or equal to LEVEL
, then the program will abort execution with abort(3). Say $SOL_LOG_ABORT=ERROR
, then it will abort on SOL_LOG_LEVEL_CRITICAL or SOL_LOG_LEVEL_ERROR. $SOL_LOG_SHOW_COLORS=
[0|1] will disable or enable the color output in functions that support it such as sol_log_print_function_stderr(). Defaults to enabled if terminal supports it. $SOL_LOG_SHOW_FILE=
[0|1] will disable or enable the file name in output. Enabled by default. $SOL_LOG_SHOW_FUNCTION=
[0|1] will disable or enable the function name in output. Enabled by default. $SOL_LOG_SHOW_LINE=
[0|1] will disable or enable the line number in output. Enabled by default.domain | where the message belongs to. |
message_level | the level of the message such as SOL_LOG_LEVEL_ERROR. |
file | the source file name that originated the message. |
function | the function that originated the message. |
line | the source file line number that originated the message. |
format | printf(3) format string for the extra arguments. It does not need trailing "\n" as this will be enforced. |
|
inlinestatic |
Standard logging function that send to standard error output.
This function must exist in every platform and is the default if no custom function is set.
|
inlinestatic |
Set the logging level that should trigger the program to abort.
level | Logging level |
|
inlinestatic |
Set the global domain maximum level to level
.
level | Logging level |
|
inlinestatic |
Set the function to print out log messages.
The function will be called with sanitized values for domain, file, function, format.
The function is called with the first argument data
being the same pointer given to this function as data parameter.
the function to use to print out messages. If NULL , then sol_log_print_function_stderr() is used. | |
data | the context to give back to print when it is called. |
|
inlinestatic |
Enable/Disables the use of colors in logging messages.
enabled | Enables color if true , disables if false |
|
inlinestatic |
Enable/Disables the output of source file's name in logging messages.
enabled | Enables file's name output if true , disables if false |
|
inlinestatic |
Enable/Disables the output of function's name containing the logging messages.
enabled | Enables function's name output if true , disables if false |
|
inlinestatic |
Enable/Disables the output of the line number in logging messages.
enabled | Enables line number output if true , disables if false |
|
inlinestatic |
Similar to sol_log_print, but called with va_list
instead of a variable number of arguments.
domain | where the message belongs to. |
message_level | the level of the message such as SOL_LOG_LEVEL_ERROR. |
file | the source file name that originated the message. |
function | the function that originated the message. |
line | the source file line number that originated the message. |
format | printf(3) format string for the extra arguments. It does not need trailing "\n" as this will be enforced. |
args | Variables list. |
struct sol_log_domain* sol_log_global_domain |
Global logging domain.
Log domain is a way to provide a scope or category to messages that can be used for filtering in addition to log levels.