Skip to content

ESP LOG redirect to own function bug. #4346

Closed
@zekageri

Description

@zekageri

If i set the esp_log_set_vprintf(redirectToF_System); than my function is never called when ESP crashes.

static char log_print_buffer[512];
static char APP_NAME[] = "My_Home";
static char Crash_File_Path[] = "/Crash_LOGS.txt";

int redirectToF_System(const char *szFormat, va_list args) {
    int ret = vsnprintf(log_print_buffer, sizeof(log_print_buffer), szFormat, args);
    if (ret >= 0){
        File g;
        if(LITTLEFS.exists(Crash_File_Path)){
            g = LITTLEFS.open(Crash_File_Path, "a");
        }else{
            g = LITTLEFS.open(Crash_File_Path, "w");
        }
        if (!g) {}else{
            g.write((uint8_t *)log_print_buffer, (size_t)ret);
        }
        g.close();
    }
    return ret;
}
static const inline void Crash_Log_Init(){
    esp_log_set_vprintf(redirectToF_System);
    esp_log_level_set("*", ESP_LOG_VERBOSE);
    //LITTLEFS.remove(Crash_File_Path);
    ESP_LOGI(APP_NAME, "Writing via ESP_LOGI!\n");
    esp_log_write(ESP_LOG_VERBOSE, APP_NAME, "I can write like this all day.\n"); // THIS LINE IS WORKING PROPERLY!
}
void setup(){
Serial.begin(115200);
Crash_Log_Init();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions