Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用户希望只有某些level的LOG才写入文件 #137

Open
xiongyu0523 opened this issue Apr 24, 2023 · 1 comment
Open

用户希望只有某些level的LOG才写入文件 #137

xiongyu0523 opened this issue Apr 24, 2023 · 1 comment

Comments

@xiongyu0523
Copy link

写FLASH/文件系统的操作,不应该在PORT层中,用户也许会希望控制某个级别的LOG,来决定是否写入FLASH/文件系统。
比如, assert, error, warning写入文件系统,而其他lv不写入。

目前我的做法是简单的复用了FMT,在elog.c中来决定是根据标志来决定是否写入文件/FLASH。
由于FMT是格式化用的,可能不是很妥当,但这样做法比较灵活,也可以单独设置一个FILE level,大于某个LV的来决定是否要写入文件。

typedef enum {
    ELOG_FMT_LVL    = 1 << 0, /**< level */
    ELOG_FMT_TAG    = 1 << 1, /**< tag */
    ELOG_FMT_TIME   = 1 << 2, /**< current time */
    ELOG_FMT_P_INFO = 1 << 3, /**< process info */
    ELOG_FMT_T_INFO = 1 << 4, /**< thread info */
    ELOG_FMT_DIR    = 1 << 5, /**< file directory and name */
    ELOG_FMT_FUNC   = 1 << 6, /**< function name */
    ELOG_FMT_LINE   = 1 << 7, /**< line number */
#ifdef ELOG_FILE_ENABLE
    ELOG_FMT_FILE_SAVE = 1 << 8, /**< file write */
#endif
} ElogFmtIndex;
#ifdef ELOG_FILE_ENABLE
    if (get_fmt_enabled(level, ELOG_FMT_FILE_SAVE)) {
        elog_file_write(log_buf, log_len);
    }
#endif
@xiongyu0523 xiongyu0523 changed the title 写FLASH/文件系统 用户希望只有某些level的LOG才写入文件 Apr 24, 2023
@armink
Copy link
Owner

armink commented Apr 30, 2023

在 elog 的输出接口中过滤一下日志级别就可以了

https://github.com/armink/EasyLogger/blob/master/easylogger/port/elog_port.c#L60-L64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants