i want to wrapper for esp_log
void Log(esp_log_level_t level, const char* tag, const char* format, ...)
{
va_list va;
va_start(va, format);
printf(format, va);
ESP_LOGI(tag, format, va);
va_end(va);
}
Severity Code Description Project File Line Suppression State
Error [Clang IntelliSense] Error: expected ')' BakelorEDK C:\Users\xxxx\source\embed\Embedded\Core\\components\Core\Log.cpp 14
How to pass parameter to ESP_LOGI?
Re: How to pass parameter to ESP_LOGI?
btw. i don't want #define approach. there is no usable for my scenario.
Re: How to pass parameter to ESP_LOGI?
thanks @wifive but i want to use exactly esp_logi(), esp_loge() etc. because i want colorizing and globally set log level.
Re: How to pass parameter to ESP_LOGI?
Ok Solved
here is the solution.
int Log(LogType logType, const char* tag, const char* format, ...)
{
va_list vArgs;
va_start(vArgs, format);
char temp[VPRINTF_STACK_BUFFER_SIZE];
int len = vsnprintf(temp, sizeof(temp) - 1, format, vArgs);
temp[sizeof(temp) - 1] = 0;
int i;
for (i = len - 1; i >= 0; --i) {
if (temp != '\n' && temp != '\r' && temp != ' ') {
break;
}
temp = 0;
}
if (i > 0) {
switch (logType)
{
case LogType::None:
case LogType::Info:
ESP_LOGI(tag, "%s", temp);
break;
case LogType::Error:
ESP_LOGE(tag, "%s", temp);
break;
case LogType::Warning:
ESP_LOGW(tag, "%s", temp);
break;
case LogType::Debug:
ESP_LOGD(tag, "%s", temp);
break;
case LogType::Verbose:
ESP_LOGV(tag, "%s", temp);
break;
default:
break;
}
}
va_end(vArgs);
return len;
}
here is the solution.
int Log(LogType logType, const char* tag, const char* format, ...)
{
va_list vArgs;
va_start(vArgs, format);
char temp[VPRINTF_STACK_BUFFER_SIZE];
int len = vsnprintf(temp, sizeof(temp) - 1, format, vArgs);
temp[sizeof(temp) - 1] = 0;
int i;
for (i = len - 1; i >= 0; --i) {
if (temp != '\n' && temp != '\r' && temp != ' ') {
break;
}
temp = 0;
}
if (i > 0) {
switch (logType)
{
case LogType::None:
case LogType::Info:
ESP_LOGI(tag, "%s", temp);
break;
case LogType::Error:
ESP_LOGE(tag, "%s", temp);
break;
case LogType::Warning:
ESP_LOGW(tag, "%s", temp);
break;
case LogType::Debug:
ESP_LOGD(tag, "%s", temp);
break;
case LogType::Verbose:
ESP_LOGV(tag, "%s", temp);
break;
default:
break;
}
}
va_end(vArgs);
return len;
}
Who is online
Users browsing this forum: No registered users and 136 guests