Re: [RFC] Add new SYS_LOG_BACKEND_FN to sys_log


Nashif, Anas
 

Eitan,,

In principle I agree we need to support additional backends, but I do not think this fits in how it is being done in sys_log.h.
I propose to extend syslog to support custom backends without having to change the header, i.e. using hooks for example.


On 8 Sep 2016, at 08:52, Perry, Eitan <eitan.perry(a)intel.com> wrote:

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
==========
• Add the option to map SYS_LOG_BACKEND_FN to a new function, that will
Put the log message in a cyclic_buffer, depends on kconfig.
• Keep the same system log api.
• The log messages will be written to a cyclic buffer (instead of
printk / printf).
• Application developers may add various back ends, that will read the
messages from the cyclic buffer and output the data to the required
driver.

======================
Code change suggestion
======================
At: /include/misc/sys_log.h

/* decide print func */
#if defined(CONFIG_LOGGER_CYCLIC_BUF)
#include <bsp_log_cyclic_buffer.h>
#define SYS_LOG_BACKEND_FN log_cyclic_buf_put
#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 */

I do not think the above is the right approach, instead, define a hook mechanism and an interface to enable the desired backend.


Anas

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