Open luckyxrq opened 1 year ago
测试环境为
#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 */ }
对 vsnprintf 的使用确实有问题,感谢指正
vsnprintf
测试环境为
建议修改为,完美解决,已测试