Debug Log

概述

Debug Log 可将软件运行的状态、过程等信息,输出到不同的介质中并进行保存。为软件调试、维护过程中的问题追溯、性能分析、系统监控、故障预警等功能,提供参考依据。

功能特性

  • 提供不同等级的 log 输出。

  • 支持 log 输出到 UART 和 Flash。

  • 支持输出 core dump 信息。

  • 支持 stream log 输出。

用法流程

参考示例

 SDK/examples/dbglog_demo

API 介绍

Defines

DBGLOG_VERSION
BUILD_DBGLOG_MASTER
LOG_STREAM_SEC
LOG_STREAM_ADDR_SEC
DBGLOG_DUMP_UART
DBGLOG_DUMP_FLASH
DBGLOG_DUMP_FULL
DBGLOG_DUMP_MINI
DBGLOG_LOG(module, lvl, fmt, ...)
DBGLOG_INFO(module, fmt, ...)
DBGLOG_WARNING(module, fmt, ...)
DBGLOG_ERROR(module, fmt, ...)
DBGLOG_LOG_RAW(module, fmt, ...)
get_param_id(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, ...)
get_param_num(...)
DBGLOG_STREAM_LOG(module, lvl, fmt, ...)
DBGLOG_STREAM_VERBOSE(module, fmt, ...)
DBGLOG_STREAM_DEBUG(module, fmt, ...)
DBGLOG_STREAM_INFO(module, fmt, ...)
DBGLOG_STREAM_WARNING(module, fmt, ...)
DBGLOG_STREAM_ERROR(module, fmt, ...)

Typedefs

typedef struct wq_dbglog_common_header wq_dbglog_common_header_t
typedef struct file_info file_info_t
typedef struct wq_dbglog_stream_log_header wq_dbglog_stream_log_header_t
typedef struct wq_dbglog_raw_log_header wq_dbglog_raw_log_header_t
typedef struct wq_dbglog_crash_log_header wq_dbglog_crash_log_header_t

Enums

enum DBGLOG_LEVEL

Values:

enumerator DBGLOG_LEVEL_ALL

Log level all

enumerator DBGLOG_LEVEL_VERBOSE

Log level verbose

enumerator DBGLOG_LEVEL_DEBUG

Log level debug

enumerator DBGLOG_LEVEL_INFO

Log level info

enumerator DBGLOG_LEVEL_WARNING

Log level warning

enumerator DBGLOG_LEVEL_ERROR

Log level error

enumerator DBGLOG_LEVEL_CRITICAL

Log level critical

enumerator DBGLOG_LEVEL_NONE

Log level none, no log output

enumerator DBGLOG_LEVEL_MAX

Functions

uint8_t wq_dbglog_stream_log_write(uint8_t module_id, DBGLOG_LEVEL level, uint16_t file_id, uint16_t line_num, uint32_t param_num, ...)

This function is used to write stream log for dbglog.

参数:
  • module_id -- is struct the stream log of header's module id.

  • level -- is struct the stream log of header's level.

  • file_id -- is struct the stream log of header's file id.

  • line_num -- is struct the stream log of header's line number.

  • param_num -- is the number of parameter which generated when pre-process.

返回:

uint8_t RET_OK or RET_NOMEM.

uint8_t wq_dbglog_stream_log_write_addr(uint8_t module_id, DBGLOG_LEVEL lvl, const char **out_addr, uint32_t param_num, ...)

This function is used to write stream log for dbglog.

参数:
  • module_id -- is struct the stream log of header's module id.

  • lvl -- is struct the stream log of header's level.

  • out_addr -- is struct the stream log of header's fmt address.

  • param_num -- is the number of parameter which generated when pre-process.

返回:

uint8_t RET_OK or RET_NOMEM.

uint8_t wq_dbglog_raw_log_write(uint8_t module_id, const char *format, ...)

This function is used to write raw log for dbglog.

参数:
  • module_id -- is struct the stream log of header's module id.

  • format -- is the format of dbglog.

  • ... --

返回:

uint8_t RET_OK or RET_FAIL or RET_NOMEM.

uint8_t wq_dbglog_crash_log_write(const uint8_t *buffer, uint8_t length)

This function is used to write crash buffer info for dbglog.

参数:
  • buffer -- is the pointer of write buffer.

  • length -- is the length of write buffer.

返回:

uint8_t RET_OK.

uint8_t wq_dbglog_buffer_write_crash(const uint8_t *buffer, uint8_t length)

This function is used to write crash buffer info for dbglog.

参数:
  • buffer -- is the pointer of write buffer.

  • length -- is the length of write buffer.

返回:

uint8_t RET_OK.

void wq_dbglog_init(void)

This function is used to init dbglog module.

uint8_t wq_dbglog_set_log_level(uint8_t module, uint8_t level)

Set output log level.

// Example of using wq_dbglog_set_log_level to set OTA module with log level error:
wq_dbglog_set_log_level(WQ_OTA_MID, DBGLOG_LEVEL_ERROR);

// Example of using wq_dbglog_set_log_level to set ALL modules with log level critical:
wq_dbglog_set_log_level(0, DBGLOG_LEVEL_ERROR);
参数:
  • module -- Module to be set

  • level -- The level to be set to

返回:

uint8_t RET_OK for success, otherwise fail.

uint8_t wq_dbglog_set_coredump_mode_io(uint8_t coredump_mode, uint8_t coredump_io)

Set coredump mode and io.

参数:
  • coredump_mode -- coredump mode, minidump or full dump

  • coredump_io -- Flash dump or uart dump

返回:

uint8_t RET_OK for success, otherwise fail.

uint8_t wq_dbglog_get_dump_mode(void)

Get dbglog coredump mode.

返回:

uint8_t coredump mode in dbglog

uint8_t wq_dbglog_set_log_io(uint8_t log_io)

Set dbglog io mode.

返回:

uint8_t io mode in dbglog

int8_t wq_dbglog_get_log_io(uint8_t *log_io)

Get dbglog io mode.

返回:

int8_t RET_OK for success, otherwise fail.

uint8_t wq_dbglog_level_check(uint8_t module_id, DBGLOG_LEVEL level)

Dbglog output level check.

参数:
  • module_id -- check log module_id

  • level -- filter level

返回:

uint8_t 1 means can be output

uint8_t wq_dbglog_stream_log_write_verbose(uint8_t module_id, uint32_t file_line, uint32_t param_num, ...)

This function is used to write stream log for dbglog.

参数:
  • module_id -- is struct the stream log of header's module id.

  • file_line -- high 16-bit is file id, low 16bit is line number.

  • param_num -- is the number of parameter which generated when pre-process.

返回:

uint8_t RET_OK or RET_NOMEM.

uint8_t wq_dbglog_stream_log_write_debug(uint8_t module_id, uint32_t file_line, uint32_t param_num, ...)

This function is used to write stream log for dbglog.

参数:
  • module_id -- is struct the stream log of header's module id.

  • file_line -- high 16-bit is file id, low 16bit is line number.

  • param_num -- is the number of parameter which generated when pre-process.

返回:

uint8_t RET_OK or RET_NOMEM.

uint8_t wq_dbglog_stream_log_write_info(uint8_t module_id, uint32_t file_line, uint32_t param_num, ...)

This function is used to write stream log for dbglog.

参数:
  • module_id -- is struct the stream log of header's module id.

  • file_line -- high 16-bit is file id, low 16bit is line number.

  • param_num -- is the number of parameter which generated when pre-process.

返回:

uint8_t RET_OK or RET_NOMEM.

uint8_t wq_dbglog_stream_log_write_warning(uint8_t module_id, uint32_t file_line, uint32_t param_num, ...)

This function is used to write stream log for dbglog.

参数:
  • module_id -- is struct the stream log of header's module id.

  • file_line -- high 16-bit is file id, low 16bit is line number.

  • param_num -- is the number of parameter which generated when pre-process.

返回:

uint8_t RET_OK or RET_NOMEM.

uint8_t wq_dbglog_stream_log_write_error(uint8_t module_id, uint32_t file_line, uint32_t param_num, ...)

This function is used to write stream log for dbglog.

参数:
  • module_id -- is struct the stream log of header's module id.

  • file_line -- high 16-bit is file id, low 16bit is line number.

  • param_num -- is the number of parameter which generated when pre-process.

返回:

uint8_t RET_OK or RET_NOMEM.

uint16_t wq_get_current_dbglog_coreid(void)

This function is used to get debug module core id.

返回:

uint16_t current debug core id.

uint16_t wq_get_dbglog_coreid(WQ_CORES core_id)

This function is used to get debug module core id.

返回:

uint16_t debug core id. if value < 0 ,id is abnormal

struct wq_dbglog_common_header

Public Members

uint32_t timestamp

log timestamp. now unit is rtc cycle

uint16_t core_id

Indicate which core this log belongs

uint16_t sequence_num

log sequence number, for log tool check whether the log is missing

uint16_t version

log version,for log tool compatibility

uint16_t payload_length

log payload length

struct file_info

Public Members

uint16_t file_id

log file id,now only for rom stream log

uint16_t line_num

line number,now only for rom stream log

struct wq_dbglog_stream_log_header

Public Members

wq_dbglog_common_header_t common_header

log common header

uint8_t level

log output level

uint8_t use_addr

use stream log mode,only rom stream log is not 1

uint8_t reserved

reserved

uint8_t module_id

log module id

file_info_t file_info

if use_addr == 0, use it

uint32_t out_addr

if use_addr == 1, use it

union wq_dbglog_stream_log_header::[anonymous] info
struct wq_dbglog_raw_log_header

Public Members

wq_dbglog_common_header_t common_header

log common header

uint8_t level

log output level

uint8_t reserved

reserved

uint8_t module_id

log module id

struct wq_dbglog_crash_log_header

Public Members

wq_dbglog_common_header_t common_header

log common header

uint8_t level

log output level

uint8_t reserved

reserved

uint8_t module_id

log module id