NUGU SDK Linux  1.7.6

Log functions. More...

+ Collaboration diagram for Log:

Macros

#define __FILENAME__   __FILE__
 
#define NUGU_ANSI_COLOR_BLACK   "\x1b[0;30m"
 
#define NUGU_ANSI_COLOR_BLUE   "\x1b[0;34m"
 
#define NUGU_ANSI_COLOR_BROWN   "\x1b[0;33m"
 
#define NUGU_ANSI_COLOR_CYAN   "\x1b[0;36m"
 
#define NUGU_ANSI_COLOR_DARKGRAY   "\x1b[1;30m"
 
#define NUGU_ANSI_COLOR_GREEN   "\x1b[0;32m"
 
#define NUGU_ANSI_COLOR_LIGHTBLUE   "\x1b[1;34m"
 
#define NUGU_ANSI_COLOR_LIGHTCYAN   "\x1b[1;36m"
 
#define NUGU_ANSI_COLOR_LIGHTGRAY   "\x1b[0;37m"
 
#define NUGU_ANSI_COLOR_LIGHTGREEN   "\x1b[1;32m"
 
#define NUGU_ANSI_COLOR_LIGHTMAGENTA   "\x1b[1;35m"
 
#define NUGU_ANSI_COLOR_LIGHTRED   "\x1b[1;31m"
 
#define NUGU_ANSI_COLOR_MAGENTA   "\x1b[0;35m"
 
#define NUGU_ANSI_COLOR_NORMAL   ""
 
#define NUGU_ANSI_COLOR_RECV   ""
 
#define NUGU_ANSI_COLOR_RED   "\x1b[0;31m"
 
#define NUGU_ANSI_COLOR_SEND   ""
 
#define NUGU_ANSI_COLOR_WHITE   "\x1b[1;37m"
 
#define NUGU_ANSI_COLOR_YELLOW   "\x1b[1;33m"
 
#define nugu_dbg(fmt, ...)    nugu_log(NUGU_LOG_MODULE, NUGU_LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
 Debug level error message. More...
 
#define nugu_error(fmt, ...)    nugu_log(NUGU_LOG_MODULE, NUGU_LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)
 Error level error message. More...
 
#define nugu_error_nomem()   nugu_error("Not enough memory")
 Default error message for 'Not enough memory'. More...
 
#define nugu_info(fmt, ...)    nugu_log(NUGU_LOG_MODULE, NUGU_LOG_LEVEL_INFO, fmt, ##__VA_ARGS__)
 Information level error message. More...
 
#define nugu_log(module, level, fmt, ...)
 Convenient macro to fill file, function and line information. More...
 
#define NUGU_LOG_MARK_RECV   "<-- "
 
#define NUGU_LOG_MARK_SEND   "--> "
 
#define NUGU_LOG_MODULE   NUGU_LOG_MODULE_DEFAULT
 Set default log module. More...
 
#define nugu_log_protocol_recv(level, fmt, ...)
 Protocol log message for receiving. More...
 
#define nugu_log_protocol_send(level, fmt, ...)
 Protocol log message for sending. More...
 
#define nugu_warn(fmt, ...)    nugu_log(NUGU_LOG_MODULE, NUGU_LOG_LEVEL_WARNING, fmt, ##__VA_ARGS__)
 Warning level error message. More...
 

Typedefs

typedef void(* nugu_log_handler) (enum nugu_log_module module, enum nugu_log_level level, const char *prefix, const char *msg, void *user_data)
 Custom log hook handler. More...
 

Enumerations

enum  nugu_log_level { NUGU_LOG_LEVEL_ERROR , NUGU_LOG_LEVEL_WARNING , NUGU_LOG_LEVEL_INFO , NUGU_LOG_LEVEL_DEBUG }
 log levels. More...
 
enum  nugu_log_module {
  NUGU_LOG_MODULE_DEFAULT = 0x01 , NUGU_LOG_MODULE_NETWORK = 0x02 , NUGU_LOG_MODULE_NETWORK_TRACE = 0x04 , NUGU_LOG_MODULE_AUDIO = 0x08 ,
  NUGU_LOG_MODULE_PROTOCOL = 0x10 , NUGU_LOG_MODULE_PROFILING = 0x20 , NUGU_LOG_MODULE_APPLICATION = 0x40 , NUGU_LOG_MODULE_PRESET_SDK_DEFAULT ,
  NUGU_LOG_MODULE_PRESET_DEFAULT , NUGU_LOG_MODULE_PRESET_NETWORK , NUGU_LOG_MODULE_ALL = 0xFF
}
 logging modules More...
 
enum  nugu_log_prefix {
  NUGU_LOG_PREFIX_NONE = 0 , NUGU_LOG_PREFIX_TIMESTAMP = (1 << 0) , NUGU_LOG_PREFIX_PID = (1 << 1) , NUGU_LOG_PREFIX_TID = (1 << 2) ,
  NUGU_LOG_PREFIX_LEVEL = (1 << 3) , NUGU_LOG_PREFIX_FILEPATH = (1 << 4) , NUGU_LOG_PREFIX_FILENAME = (1 << 5) , NUGU_LOG_PREFIX_FUNCTION = (1 << 6) ,
  NUGU_LOG_PREFIX_LINE = (1 << 7) , NUGU_LOG_PREFIX_DEFAULT , NUGU_LOG_PREFIX_ALL
}
 logging prefix More...
 
enum  nugu_log_system {
  NUGU_LOG_SYSTEM_STDERR , NUGU_LOG_SYSTEM_STDOUT , NUGU_LOG_SYSTEM_SYSLOG , NUGU_LOG_SYSTEM_NONE ,
  NUGU_LOG_SYSTEM_CUSTOM
}
 Back-end system that supports log output. More...
 

Functions

NUGU_API void nugu_hexdump (enum nugu_log_module module, const uint8_t *data, size_t data_size, const char *header, const char *footer, const char *lineindent)
 Hexdump the specific data to stderr. More...
 
NUGU_API enum nugu_log_level nugu_log_get_level (void)
 Get log level. More...
 
NUGU_API unsigned int nugu_log_get_modules (void)
 Get the bitset of modules. More...
 
NUGU_API enum nugu_log_prefix nugu_log_get_prefix_fields (void)
 Get the additional information fields. More...
 
NUGU_API int nugu_log_get_protocol_line_limit (void)
 Get the maximum length of each protocol log line. More...
 
NUGU_API enum nugu_log_system nugu_log_get_system (void)
 Get logging backend system. More...
 
NUGU_API void nugu_log_print (enum nugu_log_module module, enum nugu_log_level level, const char *filename, const char *funcname, int line, const char *format,...)
 logging function More...
 
NUGU_API int nugu_log_set_handler (nugu_log_handler handler, void *user_data)
 Set custom log handler. More...
 
NUGU_API void nugu_log_set_level (enum nugu_log_level level)
 Set minimum log level(debug, info, warning, error) For example, if set the level to info, debug is discarded, and only logs with info, warning, and error levels are displayed. More...
 
NUGU_API void nugu_log_set_modules (unsigned int bitset)
 Set the bitset of modules. More...
 
NUGU_API void nugu_log_set_prefix_fields (enum nugu_log_prefix field_set)
 Set the additional information fields. More...
 
NUGU_API void nugu_log_set_protocol_line_limit (int length)
 Set the maximum length of each protocol log line. More...
 
NUGU_API int nugu_log_set_system (enum nugu_log_system log_system)
 Set logging backend system. More...
 

Detailed Description

Log functions.

The log function supports standard error output and the syslog system, and you can set the handler you want if necessary.

Supported features:

The log function also supports setting logs at runtime using the environment variables below.

Macro Definition Documentation

◆ NUGU_LOG_MODULE

#define NUGU_LOG_MODULE   NUGU_LOG_MODULE_DEFAULT

Set default log module.

See also
enum nugu_log_module
nugu_log_set_modules()
nugu_log_get_modules()

◆ nugu_log

#define nugu_log (   module,
  level,
  fmt,
  ... 
)
Value:
nugu_log_print(module, level, __FILENAME__, __PRETTY_FUNCTION__, \
__LINE__, fmt, ##__VA_ARGS__)
NUGU_API void nugu_log_print(enum nugu_log_module module, enum nugu_log_level level, const char *filename, const char *funcname, int line, const char *format,...)
logging function

Convenient macro to fill file, function and line information.

Parameters
[in]modulelog module name
[in]levellogging level
[in]fmtprintf format string
See also
enum nugu_log_module
enum nugu_log_level

◆ nugu_dbg

#define nugu_dbg (   fmt,
  ... 
)     nugu_log(NUGU_LOG_MODULE, NUGU_LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)

Debug level error message.

Parameters
[in]fmtprintf format string
See also
nugu_log()

◆ nugu_info

#define nugu_info (   fmt,
  ... 
)     nugu_log(NUGU_LOG_MODULE, NUGU_LOG_LEVEL_INFO, fmt, ##__VA_ARGS__)

Information level error message.

Parameters
[in]fmtprintf format string
See also
nugu_log()

◆ nugu_warn

#define nugu_warn (   fmt,
  ... 
)     nugu_log(NUGU_LOG_MODULE, NUGU_LOG_LEVEL_WARNING, fmt, ##__VA_ARGS__)

Warning level error message.

Parameters
[in]fmtprintf format string
See also
nugu_log()

◆ nugu_error

#define nugu_error (   fmt,
  ... 
)     nugu_log(NUGU_LOG_MODULE, NUGU_LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)

Error level error message.

Parameters
[in]fmtprintf format string
See also
nugu_log()

◆ nugu_log_protocol_send

#define nugu_log_protocol_send (   level,
  fmt,
  ... 
)
Value:
nugu_log_print(NUGU_LOG_MODULE_PROTOCOL, level, NULL, NULL, -1, \
NUGU_ANSI_COLOR_SEND NUGU_LOG_MARK_SEND fmt \
NUGU_ANSI_COLOR_NORMAL, \
##__VA_ARGS__)
@ NUGU_LOG_MODULE_PROTOCOL
Definition: nugu_log.h:182

Protocol log message for sending.

Parameters
[in]levellogging level
[in]fmtprintf format string
See also
nugu_log_print()
enum nugu_log_level

◆ nugu_log_protocol_recv

#define nugu_log_protocol_recv (   level,
  fmt,
  ... 
)
Value:
nugu_log_print(NUGU_LOG_MODULE_PROTOCOL, level, NULL, NULL, -1, \
NUGU_ANSI_COLOR_RECV NUGU_LOG_MARK_RECV fmt \
NUGU_ANSI_COLOR_NORMAL, \
##__VA_ARGS__)

Protocol log message for receiving.

Parameters
[in]levellogging level
[in]fmtprintf format string
See also
nugu_log_print()
enum nugu_log_level

◆ nugu_error_nomem

#define nugu_error_nomem ( )    nugu_error("Not enough memory")

Default error message for 'Not enough memory'.

See also
nugu_error()

Typedef Documentation

◆ nugu_log_handler

typedef void(* nugu_log_handler) (enum nugu_log_module module, enum nugu_log_level level, const char *prefix, const char *msg, void *user_data)

Custom log hook handler.

Parameters
[in]modulelog module
[in]levellog level
[in]prefixgenerated additional information (e.g. timestamp, line number)
[in]msgoriginal log message
[in]user_dataThe user data passed from the callback function
See also
nugu_log_handler()
nugu_log_set_prefix_fields()

Enumeration Type Documentation

◆ nugu_log_level

log levels.

When building in release mode, logs at the warning, info, and debug levels are all ignored.

See also
nugu_log()
Enumerator
NUGU_LOG_LEVEL_ERROR 

Error level

NUGU_LOG_LEVEL_WARNING 

Warning level

NUGU_LOG_LEVEL_INFO 

Information level

NUGU_LOG_LEVEL_DEBUG 

Debug level

◆ nugu_log_system

Back-end system that supports log output.

See also
nugu_log_set_system()
nugu_log_set_handler()
Enumerator
NUGU_LOG_SYSTEM_STDERR 

Standard error

NUGU_LOG_SYSTEM_STDOUT 

Standard output

NUGU_LOG_SYSTEM_SYSLOG 

syslog

NUGU_LOG_SYSTEM_NONE 

no log

NUGU_LOG_SYSTEM_CUSTOM 

custom log handler by log_set_handler()

◆ nugu_log_prefix

logging prefix

See also
nugu_log_set_prefix_fields()
Enumerator
NUGU_LOG_PREFIX_NONE 

No prefix

NUGU_LOG_PREFIX_TIMESTAMP 

mm-dd HH:MM:SS.000

NUGU_LOG_PREFIX_PID 

Process ID

NUGU_LOG_PREFIX_TID 

Thread ID

NUGU_LOG_PREFIX_LEVEL 

D, I, W, E

NUGU_LOG_PREFIX_FILEPATH 

Full path with file name

NUGU_LOG_PREFIX_FILENAME 

File name

NUGU_LOG_PREFIX_FUNCTION 

Function name

NUGU_LOG_PREFIX_LINE 

Line number

NUGU_LOG_PREFIX_DEFAULT 

TIMESTAMP + PID + TID + LEVEL + FILENAME + LINE

NUGU_LOG_PREFIX_ALL 

All prefix

◆ nugu_log_module

logging modules

See also
nugu_log_set_modules()
nugu_log_get_modules()
Enumerator
NUGU_LOG_MODULE_DEFAULT 

Default module

NUGU_LOG_MODULE_NETWORK 

Network module

NUGU_LOG_MODULE_NETWORK_TRACE 

Network trace module

NUGU_LOG_MODULE_AUDIO 

Audio module

NUGU_LOG_MODULE_PROTOCOL 

Protocol module

NUGU_LOG_MODULE_PROFILING 

Profiling module

NUGU_LOG_MODULE_APPLICATION 

Application module

NUGU_LOG_MODULE_PRESET_SDK_DEFAULT 

Preset: Default SDK

NUGU_LOG_MODULE_PRESET_DEFAULT 

Preset: Default SDK with application

NUGU_LOG_MODULE_PRESET_NETWORK 

Preset: Network trace

NUGU_LOG_MODULE_ALL 

All modules

Function Documentation

◆ nugu_log_print()

NUGU_API void nugu_log_print ( enum nugu_log_module  module,
enum nugu_log_level  level,
const char *  filename,
const char *  funcname,
int  line,
const char *  format,
  ... 
)

logging function

Parameters
[in]modulelog module
[in]levellog level
[in]filenamesource file name (e.g. FILE)
[in]funcnamefunction name (e.g. FUNCTION)
[in]linesource file line number
[in]formatprintf format string
See also
nugu_dbg()
nugu_info()
nugu_warn()
nugu_error()

◆ nugu_log_set_system()

NUGU_API int nugu_log_set_system ( enum nugu_log_system  log_system)

Set logging backend system.

See also
enum nugu_log_system

◆ nugu_log_get_system()

NUGU_API enum nugu_log_system nugu_log_get_system ( void  )

Get logging backend system.

See also
enum nugu_log_system

◆ nugu_log_set_handler()

NUGU_API int nugu_log_set_handler ( nugu_log_handler  handler,
void *  user_data 
)

Set custom log handler.

Parameters
[in]handlercallback
[in]user_dataThe user data to be passed to the callback function
See also
nugu_log_handler

◆ nugu_log_set_prefix_fields()

NUGU_API void nugu_log_set_prefix_fields ( enum nugu_log_prefix  field_set)

Set the additional information fields.

Parameters
[in]field_setbitmask by enum nugu_log_prefix
See also
enum nugu_log_prefix

◆ nugu_log_get_prefix_fields()

NUGU_API enum nugu_log_prefix nugu_log_get_prefix_fields ( void  )

Get the additional information fields.

Returns
bitmask by enum nugu_log_prefix
See also
enum nugu_log_prefix

◆ nugu_log_set_modules()

NUGU_API void nugu_log_set_modules ( unsigned int  bitset)

Set the bitset of modules.

Parameters
[in]bitsetbitmask by enum nugu_log_prefix
See also
enum nugu_log_module

◆ nugu_log_get_modules()

NUGU_API unsigned int nugu_log_get_modules ( void  )

Get the bitset of modules.

Returns
bitmask by enum nugu_log_module
See also
enum nugu_log_module

◆ nugu_log_set_level()

NUGU_API void nugu_log_set_level ( enum nugu_log_level  level)

Set minimum log level(debug, info, warning, error) For example, if set the level to info, debug is discarded, and only logs with info, warning, and error levels are displayed.

Parameters
[in]levellog level

◆ nugu_log_get_level()

NUGU_API enum nugu_log_level nugu_log_get_level ( void  )

Get log level.

Returns
log level

◆ nugu_log_set_protocol_line_limit()

NUGU_API void nugu_log_set_protocol_line_limit ( int  length)

Set the maximum length of each protocol log line.

Parameters
[in]lengthline length. -1 means unlimited.

◆ nugu_log_get_protocol_line_limit()

NUGU_API int nugu_log_get_protocol_line_limit ( void  )

Get the maximum length of each protocol log line.

Returns
line length. -1 means unlimited.

◆ nugu_hexdump()

NUGU_API void nugu_hexdump ( enum nugu_log_module  module,
const uint8_t *  data,
size_t  data_size,
const char *  header,
const char *  footer,
const char *  lineindent 
)

Hexdump the specific data to stderr.

Parameters
[in]modulelog module
[in]datamemory address to hexdump
[in]data_sizesize
[in]headermessage to be printed at the top of hexdump
[in]footermessage to be printed at the bottom of hexdump
[in]lineindentmessage to be printed at the beginning of each line