AM263x MCU+ SDK  09.02.00
Control logging

Introduction

Files

file  ub_logging.h
 Control logging by levels and categories.
 

Functions

void ub_console_debug_select_print (bool console, bool debug, const char *astr)
 output to console out and debug out by selection More...
 
const char * ub_log_initstr_override (const char *ns, const char *os)
 override 'istr' of ub_log_inig More...
 
void ub_log_init (const char *istr)
 initialize logging by a string More...
 
int ub_log_add_category (const char *catstr)
 add a category of logging at the bottom of the index More...
 
int ub_log_print (int cat_index, int flags, ub_dbgmsg_level_t level, const char *astr)
 print log message More...
 
bool ub_clog_on (int cat_index, ub_dbgmsg_level_t level)
 check if console log is enabled or not for the indicated cat_index and level More...
 
bool ub_dlog_on (int cat_index, ub_dbgmsg_level_t level)
 check if debug log is enabled or not for the indicated cat_index and level More...
 
int ub_log_change (int cat_index, ub_dbgmsg_level_t clevel, ub_dbgmsg_level_t dlevel)
 change console log level to clevel, and debug log level to delevl More...
 
int ub_log_return (int cat_index)
 return console log level and console log level to the previous status More...
 
void ub_log_flush (void)
 flush out messages on the both of cosole log and debug log More...
 

Typedefs

typedef int ub_dbgmsg_level_t
 This defines different logging levels. More...
 

Macros

#define UBL_NONE   0
 
#define UBL_FATAL   1
 
#define UBL_ERROR   2
 
#define UBL_WARN   3
 
#define UBL_INFO   4
 
#define UBL_INFOV   5
 
#define UBL_DEBUG   6
 
#define UBL_DEBUGV   7
 
#define MAX_LOGMSG_CATEGORIES   16
 maximum number of categories More...
 
#define DBGMSG_LEVEL_MARK   {"NON", "FTL", "ERR", "WRN", "INF", "IFV", "DBG", "DBV"}
 3-charcter string to represent each logging level More...
 
#define UBL_TS_BIT_FIELDS   3
 lowest 2 bits are used for TS Clock type, use ub_clocktype_t UB_CLOCK_DEFAULT means no-timestamp More...
 
#define UB_LOG_COMPILE_LEVEL   UBL_DEBUGV
 
#define UB_LOG_IS_COMPILED(level)   (UB_LOG_COMPILE_LEVEL >= level)
 
#define UB_LOG_HELPER(level, tstype, ...)
 
#define UB_LOG_UBL_DEBUGV(...)   UB_LOG_HELPER(UBL_DEBUGV, 0, __VA_ARGS__)
 
#define UB_TLOG_UBL_DEBUGV(...)   UB_LOG_HELPER(UBL_DEBUGV, UB_LOGTSTYPE, __VA_ARGS__)
 
#define UB_LOG_UBL_DEBUG(...)   UB_LOG_HELPER(UBL_DEBUG, 0, __VA_ARGS__)
 
#define UB_TLOG_UBL_DEBUG(...)   UB_LOG_HELPER(UBL_DEBUG, UB_LOGTSTYPE, __VA_ARGS__)
 
#define UB_LOG_UBL_INFOV(...)   UB_LOG_HELPER(UBL_INFOV, 0, __VA_ARGS__)
 
#define UB_TLOG_UBL_INFOV(...)   UB_LOG_HELPER(UBL_INFOV, UB_LOGTSTYPE, __VA_ARGS__)
 
#define UB_LOG_UBL_INFO(...)   UB_LOG_HELPER(UBL_INFO, 0, __VA_ARGS__)
 
#define UB_TLOG_UBL_INFO(...)   UB_LOG_HELPER(UBL_INFO, UB_LOGTSTYPE, __VA_ARGS__)
 
#define UB_LOG_UBL_WARN(...)   UB_LOG_HELPER(UBL_WARN, 0, __VA_ARGS__)
 
#define UB_TLOG_UBL_WARN(...)   UB_LOG_HELPER(UBL_WARN, UB_LOGTSTYPE, __VA_ARGS__)
 
#define UB_LOG_UBL_ERROR(...)   UB_LOG_HELPER(UBL_ERROR, 0, __VA_ARGS__)
 
#define UB_TLOG_UBL_ERROR(...)   UB_LOG_HELPER(UBL_ERROR, UB_LOGTSTYPE, __VA_ARGS__)
 
#define UB_LOG_UBL_FATAL(...)   UB_LOG_HELPER(UBL_FATAL, 0, __VA_ARGS__)
 
#define UB_TLOG_UBL_FATAL(...)   UB_LOG_HELPER(UBL_FATAL, UB_LOGTSTYPE, __VA_ARGS__)
 
#define UB_LOG_UBL_NONE(...)
 
#define UB_TLOG_UBL_NONE(...)
 
#define UBL_OVERRIDE_ISTR(x, y)   ub_log_initstr_override(x,UBB_GETENV(y))
 override valuse 'x' to the value of the environment variable 'y' More...
 
#define PRINT_FORMAT_ATTRIBUTE1   __attribute__((format (printf, 1, 2)))
 let the compiler show warning when printf type format is wrong More...
 
#define PRINT_FORMAT_ATTRIBUTE4   __attribute__((format (printf, 4, 5)))
 format starts at 4th argument More...
 

Macro Definition Documentation

◆ UBL_NONE

#define UBL_NONE   0

◆ UBL_FATAL

#define UBL_FATAL   1

◆ UBL_ERROR

#define UBL_ERROR   2

◆ UBL_WARN

#define UBL_WARN   3

◆ UBL_INFO

#define UBL_INFO   4

◆ UBL_INFOV

#define UBL_INFOV   5

◆ UBL_DEBUG

#define UBL_DEBUG   6

◆ UBL_DEBUGV

#define UBL_DEBUGV   7

◆ MAX_LOGMSG_CATEGORIES

#define MAX_LOGMSG_CATEGORIES   16

maximum number of categories

◆ DBGMSG_LEVEL_MARK

#define DBGMSG_LEVEL_MARK   {"NON", "FTL", "ERR", "WRN", "INF", "IFV", "DBG", "DBV"}

3-charcter string to represent each logging level

◆ UBL_TS_BIT_FIELDS

#define UBL_TS_BIT_FIELDS   3

lowest 2 bits are used for TS Clock type, use ub_clocktype_t UB_CLOCK_DEFAULT means no-timestamp

◆ UB_LOG_COMPILE_LEVEL

#define UB_LOG_COMPILE_LEVEL   UBL_DEBUGV

◆ UB_LOG_IS_COMPILED

#define UB_LOG_IS_COMPILED (   level)    (UB_LOG_COMPILE_LEVEL >= level)

◆ UB_LOG_HELPER

#define UB_LOG_HELPER (   level,
  tstype,
  ... 
)
Value:
{ \
char coutstr[UB_CHARS_IN_LINE]; \
(void)snprintf(coutstr, UB_CHARS_IN_LINE, __VA_ARGS__); \
(void)ub_log_print(UB_LOGCAT, tstype, level, coutstr); \
}

◆ UB_LOG_UBL_DEBUGV

#define UB_LOG_UBL_DEBUGV (   ...)    UB_LOG_HELPER(UBL_DEBUGV, 0, __VA_ARGS__)

◆ UB_TLOG_UBL_DEBUGV

#define UB_TLOG_UBL_DEBUGV (   ...)    UB_LOG_HELPER(UBL_DEBUGV, UB_LOGTSTYPE, __VA_ARGS__)

◆ UB_LOG_UBL_DEBUG

#define UB_LOG_UBL_DEBUG (   ...)    UB_LOG_HELPER(UBL_DEBUG, 0, __VA_ARGS__)

◆ UB_TLOG_UBL_DEBUG

#define UB_TLOG_UBL_DEBUG (   ...)    UB_LOG_HELPER(UBL_DEBUG, UB_LOGTSTYPE, __VA_ARGS__)

◆ UB_LOG_UBL_INFOV

#define UB_LOG_UBL_INFOV (   ...)    UB_LOG_HELPER(UBL_INFOV, 0, __VA_ARGS__)

◆ UB_TLOG_UBL_INFOV

#define UB_TLOG_UBL_INFOV (   ...)    UB_LOG_HELPER(UBL_INFOV, UB_LOGTSTYPE, __VA_ARGS__)

◆ UB_LOG_UBL_INFO

#define UB_LOG_UBL_INFO (   ...)    UB_LOG_HELPER(UBL_INFO, 0, __VA_ARGS__)

◆ UB_TLOG_UBL_INFO

#define UB_TLOG_UBL_INFO (   ...)    UB_LOG_HELPER(UBL_INFO, UB_LOGTSTYPE, __VA_ARGS__)

◆ UB_LOG_UBL_WARN

#define UB_LOG_UBL_WARN (   ...)    UB_LOG_HELPER(UBL_WARN, 0, __VA_ARGS__)

◆ UB_TLOG_UBL_WARN

#define UB_TLOG_UBL_WARN (   ...)    UB_LOG_HELPER(UBL_WARN, UB_LOGTSTYPE, __VA_ARGS__)

◆ UB_LOG_UBL_ERROR

#define UB_LOG_UBL_ERROR (   ...)    UB_LOG_HELPER(UBL_ERROR, 0, __VA_ARGS__)

◆ UB_TLOG_UBL_ERROR

#define UB_TLOG_UBL_ERROR (   ...)    UB_LOG_HELPER(UBL_ERROR, UB_LOGTSTYPE, __VA_ARGS__)

◆ UB_LOG_UBL_FATAL

#define UB_LOG_UBL_FATAL (   ...)    UB_LOG_HELPER(UBL_FATAL, 0, __VA_ARGS__)

◆ UB_TLOG_UBL_FATAL

#define UB_TLOG_UBL_FATAL (   ...)    UB_LOG_HELPER(UBL_FATAL, UB_LOGTSTYPE, __VA_ARGS__)

◆ UB_LOG_UBL_NONE

#define UB_LOG_UBL_NONE (   ...)

◆ UB_TLOG_UBL_NONE

#define UB_TLOG_UBL_NONE (   ...)

◆ UBL_OVERRIDE_ISTR

#define UBL_OVERRIDE_ISTR (   x,
 
)    ub_log_initstr_override(x,UBB_GETENV(y))

override valuse 'x' to the value of the environment variable 'y'

Note
UBB_GETENV must be defined before this macro is called.

◆ PRINT_FORMAT_ATTRIBUTE1

#define PRINT_FORMAT_ATTRIBUTE1   __attribute__((format (printf, 1, 2)))

let the compiler show warning when printf type format is wrong

format starts at 1st argument

◆ PRINT_FORMAT_ATTRIBUTE4

#define PRINT_FORMAT_ATTRIBUTE4   __attribute__((format (printf, 4, 5)))

format starts at 4th argument

Typedef Documentation

◆ ub_dbgmsg_level_t

typedef int ub_dbgmsg_level_t

This defines different logging levels.

  • UBL_NONE No message will print on console
  • UBL_FATAL to print FATAL message on console
  • UBL_ERROR to print FATAL to ERROR message on console
  • UBL_WARN to print FATAL to WARNING message on console
  • UBL_INFO to print FATAL to INFO message on console
  • UBL_INFOV to print FATAL to INFOV message on console
  • UBL_DEBUG to print FATAL to DEBUG message on console
  • UBL_DEBUGV to print FATAL to DEBUGV message on console

Function Documentation

◆ ub_console_debug_select_print()

void ub_console_debug_select_print ( bool  console,
bool  debug,
const char *  astr 
)

output to console out and debug out by selection

Parameters
consoleselect output to console
debugselect output to debug memory
astra string to print

◆ ub_log_initstr_override()

const char* ub_log_initstr_override ( const char *  ns,
const char *  os 
)

override 'istr' of ub_log_inig

Parameters
nsoriginal 'istr'
osoverriding string
Returns
'ns' or 'os'
Note
if 'os' includes ',', the entire 'os' is returned and it overrides the entire 'istr' if 'os' one module of 'ns' like 'mod1:55m', 'mod1' part is overridden by 'os' e.g. when ns="4,mod0:44,mod1:44", os="mod1:55m" ub_log_init(ub_log_initstr_override(ns, os)) is initialized by "4,mod0:44,mod1:55m"

◆ ub_log_init()

void ub_log_init ( const char *  istr)

initialize logging by a string

Parameters
istrinitialization string
Note
an example of string is like "ubase:34r,mod1:45m,mod2:56g,mod3:23" each category string is separated by a comma, and the category initialization is a way in 'ub_log_add_category'

◆ ub_log_add_category()

int ub_log_add_category ( const char *  catstr)

add a category of logging at the bottom of the index

Parameters
catstrcategory initialization string
Returns
0 on success, -1 on error
Note
the string is like "catname:45m", 'catname' must be less than 7 characters, 4 is UBL_INFO levlel, 5 is UBL_INFOV level, 'm' is option to add monotonic clock timestamp.

◆ ub_log_print()

int ub_log_print ( int  cat_index,
int  flags,
ub_dbgmsg_level_t  level,
const char *  astr 
)

print log message

Parameters
cat_indexindex of categories, the index is defined by the initialization string in unibase_init function
flagstimestamp option is defined in lower 2 bits.
levellog level, see ub_dbgmsg_level_t
astra string to print
Returns
0 on success, -1 on error

◆ ub_clog_on()

bool ub_clog_on ( int  cat_index,
ub_dbgmsg_level_t  level 
)

check if console log is enabled or not for the indicated cat_index and level

Returns
true if enabled, otherwise false.

◆ ub_dlog_on()

bool ub_dlog_on ( int  cat_index,
ub_dbgmsg_level_t  level 
)

check if debug log is enabled or not for the indicated cat_index and level

Returns
true if enabled, otherwise false.

◆ ub_log_change()

int ub_log_change ( int  cat_index,
ub_dbgmsg_level_t  clevel,
ub_dbgmsg_level_t  dlevel 
)

change console log level to clevel, and debug log level to delevl

Returns
0 on success, -1 on error

◆ ub_log_return()

int ub_log_return ( int  cat_index)

return console log level and console log level to the previous status

Returns
0 on success, -1 on error

◆ ub_log_flush()

void ub_log_flush ( void  )

flush out messages on the both of cosole log and debug log

Note
the function depends of the callback function
UB_CHARS_IN_LINE
#define UB_CHARS_IN_LINE
Definition: unibase_macros.h:73
ub_log_print
int ub_log_print(int cat_index, int flags, ub_dbgmsg_level_t level, const char *astr)
print log message