2021-04-13 00:19:04 +08:00
|
|
|
# Logging
|
|
|
|
|
2021-09-06 16:55:37 +08:00
|
|
|
LVGL has a built-in *Log* module to inform the user about what is happening in the library.
|
2021-04-13 00:19:04 +08:00
|
|
|
|
|
|
|
## Log level
|
2021-05-21 04:25:47 +08:00
|
|
|
To enable logging, set `LV_USE_LOG 1` in `lv_conf.h` and set `LV_LOG_LEVEL` to one of the following values:
|
|
|
|
- `LV_LOG_LEVEL_TRACE` A lot of logs to give detailed information
|
|
|
|
- `LV_LOG_LEVEL_INFO` Log important events
|
|
|
|
- `LV_LOG_LEVEL_WARN` Log if something unwanted happened but didn't cause a problem
|
2021-06-09 21:10:35 +08:00
|
|
|
- `LV_LOG_LEVEL_ERROR` Only critical issues, where the system may fail
|
2021-05-21 04:25:47 +08:00
|
|
|
- `LV_LOG_LEVEL_USER` Only user messages
|
|
|
|
- `LV_LOG_LEVEL_NONE` Do not log anything
|
2021-04-13 00:19:04 +08:00
|
|
|
|
2021-05-21 04:25:47 +08:00
|
|
|
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.
|
2021-04-13 00:19:04 +08:00
|
|
|
|
2021-05-21 04:25:47 +08:00
|
|
|
## Printing logs
|
2021-04-13 00:19:04 +08:00
|
|
|
|
2021-05-21 04:25:47 +08:00
|
|
|
### Logging with printf
|
|
|
|
If your system supports `printf`, you just need to enable `LV_LOG_PRINTF` in `lv_conf.h` to send the logs with `printf`.
|
2021-04-13 00:19:04 +08:00
|
|
|
|
2021-05-21 04:25:47 +08:00
|
|
|
|
|
|
|
### Custom log function
|
2022-03-21 18:25:51 +08:00
|
|
|
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()`.
|
2021-04-13 00:19:04 +08:00
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
```c
|
2022-11-24 20:54:15 +08:00
|
|
|
void my_log_cb(lv_log_level_t level, const char * buf)
|
2021-04-13 00:19:04 +08:00
|
|
|
{
|
2021-05-21 04:25:47 +08:00
|
|
|
serial_send(buf, strlen(buf));
|
2021-04-13 00:19:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
lv_log_register_print_cb(my_log_cb);
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
## Add logs
|
|
|
|
|
2022-02-13 03:12:32 +08:00
|
|
|
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.
|