Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
sol-log.h File Reference

These routines are used for Soletta logging. More...

#include "sol-common-buildopts.h"
#include "sol-macros.h"
#include <inttypes.h>
#include <stdint.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <sys/types.h>

Go to the source code of this file.

Data Structures

struct  sol_log_domain
 Structure containing the attributes of the domain used for logging. More...
 

Macros

#define _SOL_INT_CHECK_FMT(var)
 Auxiliary macro intended to be used by SOL_INT_CHECK to format it's output. More...
 
#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_INT_CHECK_GOTO_IMPL(var, exp, label)
 
#define SOL_INT_CHECK_GOTO_IMPL_ERRNO(var, exp, err, label)
 
#define SOL_INT_CHECK_IMPL(var, exp,...)
 
#define SOL_INT_CHECK_IMPL_ERRNO(var, exp, err,...)
 
#define SOL_LOG(level, fmt,...)
 Logs to SOL_LOG_DOMAIN using the given level and format message. More...
 
#define SOL_LOG_COLOR_BLUE   "\033[34m"
 Blue color code. More...
 
#define SOL_LOG_COLOR_CYAN   "\033[36m"
 Cyan color code. More...
 
#define SOL_LOG_COLOR_GREEN   "\033[32;1m"
 Green color code. More...
 
#define SOL_LOG_COLOR_HIGH   "\033[1m"
 Highlight code. More...
 
#define SOL_LOG_COLOR_LIGHTBLUE   "\033[34;1m"
 Light Blue color code. More...
 
#define SOL_LOG_COLOR_LIGHTCYAN   "\033[36;1m"
 Light Cyan color code. More...
 
#define SOL_LOG_COLOR_LIGHTMAGENTA   "\033[35;1m"
 Light Magenta color code. More...
 
#define SOL_LOG_COLOR_LIGHTRED   "\033[31;1m"
 Light Red color code. More...
 
#define SOL_LOG_COLOR_MAGENTA   "\033[35m"
 Magenta color code. More...
 
#define SOL_LOG_COLOR_ORANGE   "\033[0;33m"
 Orange color code. More...
 
#define SOL_LOG_COLOR_RED   "\033[31m"
 Red color code. More...
 
#define SOL_LOG_COLOR_RESET   "\033[0m"
 Code to Reset the color to default. More...
 
#define SOL_LOG_COLOR_WHITE   "\033[37;1m"
 White color code. More...
 
#define SOL_LOG_COLOR_YELLOW   "\033[33;1m"
 Yellow color code. 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_domainsol_log_global_domain
 Global logging domain. More...
 

Detailed Description

These routines are used for Soletta logging.

Macro Definition Documentation

#define _SOL_INT_CHECK_FMT (   var)

Auxiliary macro intended to be used by SOL_INT_CHECK to format it's output.

Parameters
varInteger checked by SOL_INT_CHECK
#define SOL_INT_CHECK_GOTO_IMPL (   var,
  exp,
  label 
)
Value:
do { \
if (SOL_UNLIKELY((var)exp)) { \
SOL_WRN(_SOL_INT_CHECK_FMT(var), var, # exp); \
goto label; \
} \
} while (0)
#define SOL_WRN(fmt,...)
Logs a message with warning level.
Definition: sol-log.h:645
#define SOL_UNLIKELY(x)
Convenience macro for unlikely branch annotation.
Definition: sol-macros.h:201
#define _SOL_INT_CHECK_FMT(var)
Auxiliary macro intended to be used by SOL_INT_CHECK to format it's output.
Definition: sol-log.h:96
#define SOL_INT_CHECK_GOTO_IMPL_ERRNO (   var,
  exp,
  err,
  label 
)
Value:
do { \
if (SOL_UNLIKELY((var)exp)) { \
SOL_WRN(_SOL_INT_CHECK_FMT(var), var, # exp); \
errno = err; \
goto label; \
} \
} while (0)
#define SOL_WRN(fmt,...)
Logs a message with warning level.
Definition: sol-log.h:645
#define SOL_UNLIKELY(x)
Convenience macro for unlikely branch annotation.
Definition: sol-macros.h:201
#define _SOL_INT_CHECK_FMT(var)
Auxiliary macro intended to be used by SOL_INT_CHECK to format it's output.
Definition: sol-log.h:96
#define SOL_INT_CHECK_IMPL (   var,
  exp,
  ... 
)
Value:
do { \
if (SOL_UNLIKELY((var)exp)) { \
SOL_WRN(_SOL_INT_CHECK_FMT(var), var, # exp); \
return __VA_ARGS__; \
} \
} while (0)
#define SOL_WRN(fmt,...)
Logs a message with warning level.
Definition: sol-log.h:645
#define SOL_UNLIKELY(x)
Convenience macro for unlikely branch annotation.
Definition: sol-macros.h:201
#define _SOL_INT_CHECK_FMT(var)
Auxiliary macro intended to be used by SOL_INT_CHECK to format it's output.
Definition: sol-log.h:96
#define SOL_INT_CHECK_IMPL_ERRNO (   var,
  exp,
  err,
  ... 
)
Value:
do { \
if (SOL_UNLIKELY((var)exp)) { \
SOL_WRN(_SOL_INT_CHECK_FMT(var), var, # exp); \
errno = err; \
return __VA_ARGS__; \
} \
} while (0)
#define SOL_WRN(fmt,...)
Logs a message with warning level.
Definition: sol-log.h:645
#define SOL_UNLIKELY(x)
Convenience macro for unlikely branch annotation.
Definition: sol-macros.h:201
#define _SOL_INT_CHECK_FMT(var)
Auxiliary macro intended to be used by SOL_INT_CHECK to format it's output.
Definition: sol-log.h:96