diff --git a/include/utils/user_log_util.h b/include/utils/user_log_util.h index 0f6ccf1..8d543d3 100644 --- a/include/utils/user_log_util.h +++ b/include/utils/user_log_util.h @@ -11,6 +11,7 @@ typedef enum { #define USER_LOG(level, fmt, ...) user_log_print(level, "["__FILE__ ":%d] " fmt, __LINE__, ##__VA_ARGS__) +void user_log_set_level(user_log_level_t level); void user_log_print(user_log_level_t level, char *fmt, ...); #endif diff --git a/misc/agent_config.cfg.example b/misc/agent_config.cfg.example index a211e5e..e6b5b10 100644 --- a/misc/agent_config.cfg.example +++ b/misc/agent_config.cfg.example @@ -1,6 +1,10 @@ version = "1.0"; agent: { + common: { + log_level = 1; + }; + drivers: { spi: { path = "/dev/spidev0.0"; diff --git a/src/impl/user_lvgl_impl.c b/src/impl/user_lvgl_impl.c index 3a916b2..34b1aeb 100644 --- a/src/impl/user_lvgl_impl.c +++ b/src/impl/user_lvgl_impl.c @@ -55,11 +55,16 @@ void *user_lvgl_impl_fs_open_cb(lv_fs_drv_t *drv, const char *path, int oflag = (mode == LV_FS_MODE_RD) ? O_RDONLY : O_RDWR; int fd = open(canonical_path, oflag); + + USER_LOG(USER_LOG_DEBUG, "Called open() on %s, fd=%d", canonical_path, fd); + if(fd < 0) return NULL; int *ret = malloc(sizeof(fd)); if(ret != NULL) *ret = fd; + USER_LOG(USER_LOG_DEBUG, "Allocated fd %d@%p", fd, ret); + return ret; } @@ -68,7 +73,13 @@ lv_fs_res_t user_lvgl_impl_fs_close_cb(lv_fs_drv_t *drv, void *file_p) { if(fd > 0) { free(file_p); + + USER_LOG(USER_LOG_DEBUG, "Free'd fd %d@%p", fd, file_p); + close(fd); + + USER_LOG(USER_LOG_DEBUG, "Called close() on fd %d", fd); + return LV_FS_RES_OK; } return LV_FS_RES_FS_ERR; @@ -80,6 +91,9 @@ lv_fs_res_t user_lvgl_impl_fs_read_cb(lv_fs_drv_t *drv, void *file_p, void *buf, if(fd > 0) { *br = read(fd, buf, btr); + + USER_LOG(USER_LOG_DEBUG, "Called read() on fd %d, len=%d, rlen=%d", fd, btr, *br); + if(*br < 0) return LV_FS_RES_FS_ERR; return LV_FS_RES_OK; } @@ -120,6 +134,9 @@ lv_fs_res_t user_lvgl_impl_fs_seek_cb(lv_fs_drv_t *drv, void *file_p, if(fd > 0) { int new_offset = lseek(fd, pos, l_whence); + + USER_LOG(USER_LOG_DEBUG, "Called seek() on fd %d, pos=%d, whence=%d", fd, pos, l_whence); + if(new_offset < 0) return LV_FS_RES_FS_ERR; return LV_FS_RES_OK; } @@ -133,6 +150,9 @@ lv_fs_res_t user_lvgl_impl_fs_tell_cb(lv_fs_drv_t *drv, void *file_p, if(fd > 0) { *pos_p = lseek(fd, 0, LV_FS_SEEK_CUR); + + USER_LOG(USER_LOG_DEBUG, "Called tell() on fd %d, pos=%d", fd, *pos_p); + if(*pos_p < 0) return LV_FS_RES_FS_ERR; return LV_FS_RES_OK; } diff --git a/src/main.c b/src/main.c index ae901d1..0970df6 100644 --- a/src/main.c +++ b/src/main.c @@ -35,6 +35,10 @@ int main(int argc, const char *argv[]) { return -2; } + user_log_level_t log_level = USER_LOG_INFO; + user_config_lookup_int(&g_config, "agent.common.log_level", (int *)&log_level); + user_log_set_level(log_level); + char *spi_path = user_config_lookup_string(&g_config, "agent.drivers.spi.path"); if(spi_path == NULL) { USER_LOG(USER_LOG_ERROR, "Failed to find SPI device from config, using default."); diff --git a/src/utils/user_log_util.c b/src/utils/user_log_util.c index 41fe30b..815d928 100644 --- a/src/utils/user_log_util.c +++ b/src/utils/user_log_util.c @@ -3,9 +3,20 @@ #include +#include "drivers/user_config_driver.h" + #include "utils/user_log_util.h" +static user_log_level_t s_current_level = USER_LOG_DEBUG; + +void user_log_set_level(user_log_level_t level) { + s_current_level = level; +} + void user_log_print(user_log_level_t level, char *fmt, ...) { + + if(level < s_current_level) return; + char *level_str; switch(level) { case USER_LOG_DEBUG: