Logging function without runtime filtering but includes timestamp and end of line termination

Using Zephyr.

I'm looking for a process or a function to log unconditional message in the logging system including timestamp and other typical logging/display functionality.  LOG_RAW strips time stamps and EOL termination.  LOG_INF -> LOG_ERR are all conditional, not to mention have colors.  

I could write directly to the shell, but I'm counting on the messages being written to the shell and the FS (both backends working).  Ideally I want a function to call that logs to both the shell and FS, adds line termination, sets a color, and it not filterable.  

This is so I can log general process information to the logs, but is not necessarily an error or warning.  Using INF could be used with a separate logger/processor tag, but it could still be filtered out intentionally or accidently. 

PrintK and the various forms require additional line termination and don't generate the time stamp. 

Parents
  • Zephyr logging system does not seem to have a built-in function that meets all your requirements. However, you can use a combination of the available functions and features to achieve your goal.
    The LOG_PRINTK() function is the closest to what you're looking for. It unconditionally prints raw log messages, similar to the printk() function, but it goes through the logging infrastructure, thus utilizing logging modes such as deferred mode. However, it does not automatically append timestamps or line terminations.
    Timestamps can be added to log messages by using the log_set_timestamp_func() function. This function allows you to set a custom function that returns the timestamp value. If not provided, k_cycle_get or k_cycle_get_32 is used for timestamping.
    Here is an example of how you can use it:
    In this example, custom_timestamp_func is your custom function that returns the timestamp, and timestamp_freq is the frequency of your timestamp source.you can use the log_output_timestamp_freq_set() function, which sets the frequency of the timestamp. H
  • I'm sorry, these instructions are not specific enough or I'm not understanding.  log_set_timestamp_func doesn't return a timestamp, only configures how the timestamping works, only though the typical LOG_XXX functions.  

    Are you ultimately suggesting to just build a string in userspace and just pass that on to LOG_PRINTK?

    What I'd really like to see is a way to use something like LOG_MSG_SIMPLE_FUNC(_source_level...) with a custom _source or some other lower level function to bypass the filtering capabilities but retain the already built in timestamping.

Reply
  • I'm sorry, these instructions are not specific enough or I'm not understanding.  log_set_timestamp_func doesn't return a timestamp, only configures how the timestamping works, only though the typical LOG_XXX functions.  

    Are you ultimately suggesting to just build a string in userspace and just pass that on to LOG_PRINTK?

    What I'd really like to see is a way to use something like LOG_MSG_SIMPLE_FUNC(_source_level...) with a custom _source or some other lower level function to bypass the filtering capabilities but retain the already built in timestamping.

Children
No Data
Related