Read the log file backend FS

Hello Nordic team, 

I want to be able to save the log into a file and then read it in order to send it's content via HID.

I've managed to make the log back end FS work (I can see the file's size increasing).

But when I want to read it's content I get an hard fault.

I think I need to stop the log to be written to the file before reading it.

Is there a way to do so or a specific function for this case ? 

I didn't find anything yet on zephyr repo neither on the devzone Q&A.

Thanks in advance.

Martin.

  • But when I want to read it's content I get an hard fault.

    I think I need to stop the log to be written to the file before reading it.

    I think it sounds reasonable that you should close the file before reading it. Maybe you need to even switch between writing and reading, and have some buffers where you can store data intermittently. Maybe you can also create several files, such that you can read files that are currently not being written to. I don't have any good pointers here, this is very much up how you have made the log backend write to the file system in the first place, but I think you are on the right path on how I would have solved it at least.

    Kenneth

  • Hello Kenneth, 

    Thanks for the answer.

    I've already tried to close the file, this leading to an hardfault (While closing the file).

    I'm using the Kconfig to activate the log file : 

    CONFIG_FILE_SYSTEM_IMAGE_PATH="/lfs_ext_flash"
    #Log file backend
    CONFIG_LOG_BACKEND_FS=y
    CONFIG_LOG_BACKEND_FS_DIR="/lfs_ext_flash"
    CONFIG_LOG_BACKEND_FS_FILE_SIZE=6400000
    CONFIG_LOG_BACKEND_FS_FILES_LIMIT=1

    Is there a way to re-direct the log_backend_fs to another file or to stop it at runtime ? 

    Because right now it appears that I can't do anything with this file with this feature activated.

    Best regards.

    Martin

  • Can you try to reduce size and increase the number of files? e.g.

    CONFIG_LOG_BACKEND_FS_FILE_SIZE=1000
    CONFIG_LOG_BACKEND_FS_FILES_LIMIT=1000

    That I would expect you can read files that have been filled at least?

    Kenneth

  • Looking at the example I can find it uses:

    CONFIG_LOG_BACKEND_FS_FILE_SIZE=128
    CONFIG_LOG_BACKEND_FS_FILES_LIMIT=4

    Maybe it will just go back to the first file when the last file is filled?

    Kenneth

  • I've managed to read the content of the log file using : 

    const struct log_backend *backend = log_backend_get(0);
    log_backend_deactivate(backend);
    this->Create();
    PrintAllFileChar();
    this->Close();
    log_backend_activate(backend,NULL);

    The issues I'm facing now is that I can't delete the log file recreate it and then reactivate the log_backend.

    When I do so : 

    this->Close();
    this->Delete();
    log_backend_init(backend);
    log_backend_activate(backend, NULL);

    The log doesn't write data in the file anymore.

    Am I missing somethings ? 

    The behavior that I want is that when I read the content of the file I delete all that has been read.

Related