Skip to content

Conversation

@nordic-krch
Copy link
Contributor

Log API can be used before user can explicitly initialize the logger.
In order to ensure that logger core is ready to buffer log messages
it must be initialize as early as possible. Initialization does not
include initialization of default backend since driver may not be
ready and backend is needed only when log messages are processed.

PR replaces #8742

Signed-off-by: Krzysztof Chruscinski [email protected]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @andrewboie proposed here: #8828 (comment), we could use static inline functions in order to not change behaviour when logger is enabled and disabled.

@nordic-krch; Have you tried this approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macros gives me possibility to handle variable number of arguments without using va_list. but even when inline functions would be used I need to handle the case when some variables that macro/function access disappears when logger is disabled for given module.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the log is disabled you can just make empty variadic inline functions.
I really would rather see this with inline functions at some point in the layers so that variables defined specifically for use in a log point don't generate "defined but not used" warnings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ensured, if you look at macro __LOG() (log_core.h line 169) you can see that it always evaluates to if else clause. Condition in if clause evaluates to false on compile time if log is disabled for given module and log code is not included in the binary but you will never get 'defined but not used'.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is timestamp now mandatory? If not, why we have to have default function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is mandatory. and actually there are 2 default functions. Dummy_timestamp is used between log_core_init() and log_init(). Then timestamp which is using k_cycle_get_32 is used and it can be later on replaced by a user function. k_cycle_get_32 cannot be used from the start because it may not be configured/available then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC could be 0. Are we supporting that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, i will fix that in another PR.

@codecov-io
Copy link

codecov-io commented Jul 11, 2018

Codecov Report

Merging #8842 into master will increase coverage by 0.01%.
The diff coverage is 89.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8842      +/-   ##
==========================================
+ Coverage   52.31%   52.32%   +0.01%     
==========================================
  Files         195      195              
  Lines       24732    24742      +10     
  Branches     5141     5142       +1     
==========================================
+ Hits        12939    12947       +8     
- Misses       9719     9721       +2     
  Partials     2074     2074
Impacted Files Coverage Δ
include/logging/log_msg.h 81.81% <ø> (ø) ⬆️
subsys/logging/log_msg.c 81.95% <100%> (+0.41%) ⬆️
kernel/init.c 57.97% <100%> (+0.61%) ⬆️
subsys/logging/log_core.c 72.53% <86.66%> (-0.26%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b836d6...adb82ad. Read the comment docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please introduce variables in the beginning of func

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This func can be called multiple times now. Will it cause any issues if done so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added protection

Log API can be used before user can explicitly initialize the logger.
In order to ensure that logger core is ready to buffer log messages
it must be initialize as early as possible. Initialization does not
include initialization of default backend since driver may not be
ready and backend is needed only when log messages are processed.

Signed-off-by: Krzysztof Chruscinski <[email protected]>
@nashif nashif merged commit 6b01c89 into zephyrproject-rtos:master Jul 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants