[English]

Logging(日志)

显示原文

LVGL has a built-in Log module to inform the user about what is happening in the library.


LVGL 有内置的 Log 模块来通知用户库中发生的事情。

Log level(日志等级)

显示原文

To enable logging, set LV_USE_LOG in lv_conf.h and set LV_LOG_LEVEL to one of the following values:

The events which have a higher level than the set log level will be logged too. E.g. if you LV_LOG_LEVEL_WARN, errors will be also logged.


要启用日志记录,请在 lv_conf.h 中设置 LV_USE_LOG 并将 LV_LOG_LEVEL 设置为以下值之一:

级别高于设置的日志级别的事件也将被记录。例如。如果你 LV_LOG_LEVEL_WARN,错误也会被记录。

Printing logs(打印日志)

Logging with printf(使用 printf 记录)

显示原文

If your system supports printf, you just need to enable LV_LOG_PRINTF in lv_conf.h to send the logs with printf.


如果你的系统支持 printf,你只需要在 lv_conf.h 中启用 LV_LOG_PRINTF 就可以发送带有 printf 的日志。

Custom log function(自定义日志功能)

显示原文

If you can't use printf or want to use a custom function to log, you can register a "logger" callback with lv_log_register_print_cb().

For example:


如果你不能使用 printf 或者想使用自定义函数来记录日志,你可以使用 lv_log_register_print_cb() 注册一个“记录器”回调。

例如:

void my_log_cb(lv_log_level_t level, const char * buf)
{
  serial_send(buf, strlen(buf));
}

...


lv_log_register_print_cb(my_log_cb);

Add logs(添加日志)

显示原文

You can also use the log module via the LV_LOG_TRACE/INFO/WARN/ERROR/USER(text) or LV_LOG(text) functions. Here:

  • LV_LOG_TRACE/INFO/WARN/ERROR/USER(text) append following information to your text

  • Log Level

  • __FILE__

  • __LINE__

  • __func__

  • LV_LOG(text) is similar to LV_LOG_USER but has no extra information attached.


您还可以通过 LV_LOG_TRACE/INFO/WARN/ERROR/USER(text)LV_LOG(text) 函数使用日志模块。这里:

  • LV_LOG_TRACE/INFO/WARN/ERROR/USER(text) append following information to your text

  • Log Level

  • __FILE__

  • __LINE__

  • __func__

  • LV_LOG(text) is similar to LV_LOG_USER but has no extra information attached.

API

lv_log.h