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

  • 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.

  • Hi Ben, thanks for your question and the update.

    I haven't been able to get to this case yet, but I hope to have time tomorrow. Just wanted to let you know.

    Best regards,

    Raoul

  • Hello Raoul,

    No problem at all. Thank you. Sounds good. Slight smile

    Best regards,

    Ben

  • Hi Ben, sorry for the delay.

    Thanks again for your descriptions so far. The logging system is a beast, I can't say I understand the internals well.

    Ben_R831 said:
    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.

    Yes, log messages are queued, although I didn't realise this persisted even past the disabling and reenabling of a logging backend. Are you saying this queueing is unwanted, you don't care about missing messages? Or do you have a second backend set up?

    Ben_R831 said:
    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.

    Strange, so the log_backend_get_by_name() function that you backported doesn't consistently work?

    I've been looking at other options that are available in NCS v1.7.0 (assuming that that's currently a strict requirement for you) and one other option I can think of is to use run-time filtering (discussed in for example this case).

    You have to enable CONFIG_LOG_RUNTIME_FILTERING=y and then use log_filter_set() to set the level to 0.

    Unfortunately I'm not actually sure if this will prevent your hard faults from occurring, but it might be worth trying.

    By the way, can I ask why you need to unmount the filesystem? Are you removing an SD card or similar? Just asking in case your actual objective can be achieved in a different way.

    Best regards,

    Raoul

Related