[RFC] [RFC] Add new SYS_LOG_BACKEND_FN to sys_log


Havusha, Yossi <yossi.havusha@...>
 

[devel] [RFC] Add new SYS_LOG_BACKEND_FN to sys_log.h
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

========
Overview
========
    Current system log implementation:
    • When using system log API (SYS_LOG_ERR(…), SYS_LOG_WRN(…),
      SYS_LOG_INF(…), SYS_LOG_DBG(…) ), each of the four SYS_LOG_X macros is
      calling the same macro - SYS_LOG_BACKEND_FN that should output the log
      message. 
    • SYS_LOG_BACKEND_FN is mapped to printk or printf according to kconfig.

=====
Goals
=====
    • Have the ability to use various back ends to output the messages,
      i.e. different UART than the console, SPI, flash, FS, etc..
    • The users should use the log in asynchronous way (i.e. not wait to IO
      drivers).

==========
Suggestion
==========
    • Keep the same system log api.  
    • Add the option to map SYS_LOG_BACKEND_FN to a new function hook
    • Users may register their own function to the hook function
    • Application developers may add various back ends, that will use their
      hook function to output the data to the required driver.
    • Multiple back ends at the same time can be also implemented at the same
      approach - the hook function will call all back ends

======================
Code change suggestion
======================
    At: /include/misc/sys_log.h
    
    /* setup the hook func */   
    extern void (*_syslog_hook)(const char *fmt, ...);
    void _syslog_hook_install(void (*hook)(const char *, ...));
   
    /* decide print func */
    #if defined(CONFIG_LOGGER_EXTERNAL_HOOK)
    #define SYS_LOG_BACKEND_FN _syslog_hook
    #elif defined(CONFIG_STDOUT_CONSOLE)
    #include <stdio.h>
    #define SYS_LOG_BACKEND_FN printf
    #else
    #include <misc/printk.h>
    #define SYS_LOG_BACKEND_FN printk
    #endif /* CONFIG_STDOUT_CONSOLE */

     

---------------------------------------------------------------------
A member of the Intel Corporation group of companies

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

Join devel@lists.zephyrproject.org to automatically receive all group messages.