Disable SHELL logger backend at runtime

Hi,

I have the logging module activated with two backends UART and RTT. The SHELL module is using UART. I'm trying to control the SHELL UART logging backend at runtime, as I need to disable logs going through UART at certain conditions and re-enable them later.

This is the .conf file flags

CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_BACKEND_UART=y
CONFIG_SHELL_LOG_BACKEND=y

I used the z_shell_log_backend_disable() API, but I'm still seeing logs on the SHELL/UART. Is there other way to disable the shell uart logging backend?

    // disable shell log backend
    z_shell_log_backend_disable(shell_backend_uart_get_ptr()->log_backend);

Parents Reply Children
  • I managed to get it working.
     

    I used log_backend_disable() api for both SHELL and UART to completely disable logs then used log_backend_enable()  to re-enable logging.

    // to disable
        log_backend_disable(log_backend_get_by_name("shell_uart_backend"));
        log_backend_disable(log_backend_get_by_name("log_backend_uart"));
        
    // to enable
    
    log_backend_enable(
            log_backend_get_by_name("log_backend_uart"),
            NULL,
            LOG_LEVEL_INF);
    
    log_backend_enable(
            log_backend_get_by_name("shell_uart_backend"),
            (void*) shell_backend_uart_get_ptr(),
            LOG_LEVEL_INF);

Related