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

log缓冲区大小宏定义小于真实格式化输出字符串,导致shell提示符(尾行模式测试的)和打印信息始终只在第一行显示,用户感官为死机的感觉 #152

Open
luckyxrq opened this issue Apr 16, 2023 · 1 comment

Comments

@luckyxrq
Copy link

测试环境为

#define     LOG_BUFFER_SIZE    (53-6)              /**< log输出缓冲大小

connect(&m_timer,&QTimer::timeout,this,&MainUI::on_timeout);
m_timer.start(10);

void MainUI::on_timeout()
{
       shell_log_task();
       logError("2023年4月14日15:25:23");
}

建议修改为,完美解决,已测试

void logWrite(Log *log, LogLevel level, const char *fmt, ...)
{
    va_list vargs;
    int len;
    
#if LOG_USING_LOCK == 1
    logLock(log);
#endif /* LOG_USING_LOCK == 1 */
    va_start(vargs, fmt);
    len = vsnprintf(logBuffer, LOG_BUFFER_SIZE, fmt, vargs);
    va_end(vargs);

    if(len >= LOG_BUFFER_SIZE - 1 || len < 0)
    {
        logBuffer[LOG_BUFFER_SIZE -1] = 0;
        logBuffer[LOG_BUFFER_SIZE -2] ='\n';
        logBuffer[LOG_BUFFER_SIZE -3] = '\r';
        logWriteBuffer(log, level, logBuffer, LOG_BUFFER_SIZE - 1);
    }
    else
    {
        logWriteBuffer(log, level, logBuffer, len);
    }


#if LOG_USING_LOCK == 1
    logUnlock(log);
#endif /* LOG_USING_LOCK == 1 */
}
@NevermindZZT
Copy link
Owner

vsnprintf 的使用确实有问题,感谢指正

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