Runtime disable log backend FS in nRF Connect 1.7.0

Hello,

I am trying to store logs using the backend FS. However, I would like the opportunity to unmount the file system at run time. As currently that results in a hard fault as the backend is expecting the mount for the file system, I am trying to disable that backend temporarily before the unmount. 

I saw this post about disabling log backend FS. However, as I am using NCS 1.7.0, I only have log_backend_get() and log_backend_activate/deactivate(). How can I use those to reach the same effect as log_backend_disable(log_backend_get_by_name("log_backend_fs")) ?

I attempted to modify the SDK based off of this commit, but it won't work due to missing dependencies. 

Thank you,

Ben

Parents
  • An update:

    I got it working by first adding this specific section into "zephyr/include/logging/log_backend.h". 

    static inline const struct log_backend *log_backend_get_by_name(const char *backend_name)
    {
    	const struct log_backend *ptr = __log_backends_start;
    
    	while (ptr < __log_backends_end) {
    		if (strcmp(backend_name, ptr->name) == 0) {
    			return ptr;
    		}
    		ptr++;
    	}
    	return NULL;
    }

    Then, to deactivate/activate, I call:

    const struct log_backend *fslog = log_backend_get_by_name("log_backend_fs");
    void* originalCTX = fslog->cb->ctx;
    
    log_backend_deactivate(fslog);
    
    // Then to activate:
    log_backend_activate(fslog,originalCTX);

    When testing, I first tested this without reactivating and sure enough, the logs were not saved to flash after deactivation.

    But, I also noticed that when the backend is re-activated, the logs since deactivation are also stored on the flash. I am assuming it is because the backend places on a queue all messages while its deactivated.

    Any thoughts?

    Thanks,

    Ben

  • Also, as I have been running it more, I occasionally get Hard Faults and Bus Faults with the layout above. It happens once in awhile with this section of code. I also noticed that the ctx pointer is NULL.

Reply Children
No Data
Related