vendredi 8 janvier 2021

C++: Problems of file write using FILE Library when file beat process is running

I have a code for file write using FILE Library, and usually works, but I found a case where doesn't work: When the code runs concurrently with filebeat process.

I don't know this cause of the problem because my c++ project does not support debugging mode.

I am participating in an open source project developed by someone else and i am not familiar with this project yet.

This is my c++ code:

FILE *fptr;
fptr = fopen("log_path.c_str()", "w");

if (fptr == NULL) 
{
    printf("Error!");
    exit(1);
}

fprintf(fptr, "%s", log.c_str());
fclose(fptr);

Is there a any other good way to save log files?

Please give me some advice.

Aucun commentaire:

Enregistrer un commentaire