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.

  • Hmm.. what if you empty the content of the file, but keep the file?

    Kenneth

  • Is there a way to do so ? 

    For the moment I do : 

    	int ret = fs_open(&this->file, this->path.path, FS_O_WRITE);
    	if (ret < 0)
    	{
    		LOG_ERR("Error opening file: %d", ret);
    		return ret;
    	}
    	
    	ret = fs_truncate(&file, 0);
    	if (ret < 0)
    	{
    		LOG_ERR("Error truncating file: %d", ret);
    		return ret;
    	}
    	else
    	{
    		LOG_INF("File content cleared successfully");
    	}
    
    	ret = fs_seek(&this->file,
    				  0,
    				  FS_SEEK_SET);
    	fs_sync(&file);
    	fs_close(&file);

    I've check the size everything is fine the size is set to 0 and the position is at the beginning of the file.

    But as soon as I received some log message, they are written at the old end of file position and the size is increased to the original size + the new log.

    It' seems that the log_backend_fs use another stored position and size that the file system does.

    I don't understand why because in log_backend_fs.c we use:

    static struct fs_file_t fs_file;

    Martin.

  • The issues is that the struct fs_file_t is both created in the application code and in the log_backend_fs driver.

    This isn't very convenient as it is right now.

    I'm trying to figure it out how I can pass the struct as a pointer in order to modify it from the app.

    There is a ctx field in the backend struct that can be useful.

    Another way to do it will be to add the deletion in one of the log_backend api functions.

    If you have any-input how to do so I'll be glad to hear it and I can propose the changes on the zephyr github.

    Thanks in advance.

    Best regards.

    Martin.

  • Hi Martin,

    Sorry, I don't have any input here. But I am very interested if you find out more on this from the zephyr community.

    Kenneth

Related