-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Network logging overhaul #8816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Network logging overhaul #8816
Conversation
@nordic-krch If you have time, please review and check if it makes sense what I am doing when converting to new logger. |
drivers/ethernet/eth_native_posix.c
Outdated
@@ -208,7 +207,7 @@ static int eth_send(struct net_if *iface, struct net_pkt *pkt) | |||
|
|||
update_gptp(iface, pkt, true); | |||
|
|||
SYS_LOG_DBG("Send pkt %p len %d", pkt, count); | |||
NET_DBG("Send pkt %p len %d", pkt, count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is NET_DBG required? Why not use LOG_DBG directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had some issues when using logger directly. I will revisit this in next version.
Codecov Report
@@ Coverage Diff @@
## master #8816 +/- ##
=========================================
- Coverage 53.24% 52.9% -0.34%
=========================================
Files 209 210 +1
Lines 25630 25732 +102
Branches 5537 5672 +135
=========================================
- Hits 13647 13614 -33
- Misses 9787 9802 +15
- Partials 2196 2316 +120
Continue to review full report at Codecov.
|
Is this PR setting a precedent? Will every subsystem in Zephyr eventually convert from using CONFIG_SYS_LOG_* options to CONFIG_LOG_*? I feel like this PR changes the net subsystem from one set of snowflake configs.. to another set. |
yes, we will move to the new logging subsystem, not sure if much though has been put in migration from the old to the new, i.e. I would have been happy if we kept CONFIG_SYS_LOG and just changed the implementation beneath it but the issue is that there are more changes needed, it is not a 1:1 translation. Transition path based on what we have now: keep sys_log working, move to LOG everywhere, obsolete sys_log later. |
New version uploaded. I made the patches a bit more fine grained. @mike-scott I separated the lwm2m changes to two separate patches if you want to handle them separately or do not want them to be merged. About the new logger, I made a trivial and simplified test with frdm-k64f and ping. New logger but no debug options enabled:
Then same thing with new logger but various networking debug options enabled, like core, icmpv4, context etc
so basically no difference in execution between these two. Then a control run with old logging and same debug options enabled as in previous run.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General comment:
Soon we will have a console, which will be fully integrated with logger (#8872). To fully utilize capabilities of new logging subsystem I suggest the following:
-
Keep some hierarchy module names. The dynamic log management will allow you to do something like this "log enable net_tcp_*".
-
If something could be instantiated multiple times, please consider using LOG_INST*. Then you will be able to filter logs from given instance(s).
drivers/net/Kconfig
Outdated
int | ||
prompt "SLIP driver log level" | ||
depends on SYS_LOG && SLIP | ||
config SLIP_LOG_LEVEL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have a choice here instead of numeric value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I briefly looked about this and it is not possible to do things like this
default y if NET_LOG_LEVEL > 3
in Kconfig if we use choice fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could have template like:
choice
prompt "Module logging level"
config MODULE_LOG_LEVEL_OFF
bool "Off"
config MODULE_LOG_LEVEL_ERR
bool "Error"
config MODULE_LOG_LEVEL_WRN
bool "Warning"
config MODULE_LOG_LEVEL_INF
bool "Info"
config MODULE_LOG_LEVEL_DBG
bool "Debug"
endchoice
config MODULE_LOG_LEVEL
int
default 0 if MODULE_LOG_LEVEL_OFF
default 1 if MODULE_LOG_LEVEL_ERR
default 2 if MODULE_LOG_LEVEL_WRN
default 3 if MODULE_LOG_LEVEL_INF
default 4 if MODULE_LOG_LEVEL_DBG
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ulfalizer is it possible to have some kind of templates in kconfig. As you can see in above comment, ideally we should have common scheme for configuring logging in modules.
drivers/net/slip.c
Outdated
@@ -63,7 +66,7 @@ struct slip_context { | |||
#endif | |||
}; | |||
|
|||
#if SYS_LOG_LEVEL >= SYS_LOG_LEVEL_DEBUG | |||
#if LOG_LEVEL >= LOG_LEVEL_DBG | |||
#if defined(CONFIG_SYS_LOG_SHOW_COLOR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is #if defined(CONFIG_SYS_LOG_SHOW_COLOR)
still valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hexdump routine in slip.c needs conversion to use logger hexdump. The color check will disappear when that conversion is done.
include/logging/log.h
Outdated
@@ -280,6 +280,39 @@ int log_printk(const char *fmt, va_list ap); | |||
#endif /*CONFIG_LOG_RUNTIME_FILTERING*/ | |||
|
|||
#else /* LOG enabled for the module. */ | |||
/* No logging, so set the macros to do nothing */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, that this is not needed after recent changes in logger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jukkar, ping. This commit ("logging: Avoid compile error if debug prints are disabled") should not be part of this PR (should be its own PR, merged long ago, or maybe no longer needed).
|
||
LOG_MODULE_REGISTER(); | ||
|
||
#define NET_DBG(fmt, ...) LOG_DBG("(%p): %s: " fmt, k_current_get(), \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about "(%p): %s(): " ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omitting () from function name saves two characters without sacrificing any readability. I am not sure about the print format atm, this is what we currently print with sys_log, but of course we could change that when printing with logger.
@@ -229,7 +229,7 @@ enum net_addr_type { | |||
NET_ADDR_OVERRIDABLE, | |||
}; | |||
|
|||
#if NET_LOG_ENABLED > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use LOG_* constants instead of numeric values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this ifdef at all. Function is used only in NET_DBG(). When debug level is off, compiler will not include this function.
include/net/net_pkt.h
Outdated
@@ -687,7 +687,7 @@ static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt) | |||
NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \ | |||
CONFIG_NET_BUF_USER_DATA_SIZE, NULL) | |||
|
|||
#if defined(CONFIG_NET_DEBUG_NET_PKT) | |||
#if CONFIG_NET_LOG_LEVEL_NET_PKT > 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use LOG_* constants instead of numeric values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And probably use >= comparison for clarity. ("Logging starts at the level X", not "logging starts after the level Y".)
include/net/net_core.h
Outdated
#ifndef NET_SYS_LOG_LEVEL | ||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_NET_LEVEL | ||
#if !defined(LOG_LEVEL) | ||
#if defined(NET_LOG_LEVEL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need NET_LOG_LEVEL? Could we just use per-module LOG_LEVEL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was done like this so that networking header files can have network specific checks.
For example if LOG_LEVEL is used, it might turn on things in network header files even if networking is disabled.
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_LWM2M_LEVEL | ||
#include <logging/sys_log.h> | ||
#define LOG_MODULE_NAME ipso_light_control | ||
#define LOG_LEVEL CONFIG_SYS_LOG_LWM2M_LEVEL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to change the Kconfig naming here to NET_LOG_LWM2M_LEVEL to match the rest of the subsys/net/lib options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think I will leave to you to decide. I will remove the lwm2m patches from this PR, you can re-use them if you wish.
#define NET_LOG_ENABLED 1 | ||
#endif | ||
#define LOG_MODULE_NAME echo_server | ||
#define NET_LOG_LEVEL 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why switch to a hard coded 4 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why switch to a hard coded 4 here?
I guess it is one-to-one translation. Was:
#define NET_SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG
now:
#define NET_LOG_LEVEL 4
Except, as mentioned by @pizi-nordic, should used symbolic constants everywhere.
#define NET_LOG_ENABLED 1 | ||
#endif | ||
#define LOG_MODULE_NAME echo_server_tcp | ||
#define NET_LOG_LEVEL LOG_LEVEL_DBG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost all of the samples are using SYS_LOG_LEVEL_DEBUG elsewhere in the PR. Should we be using LOG_LEVEL_DBG (like here) instead?
subsys/net/Kconfig.hostname
Outdated
default n | ||
config NET_LOG_LEVEL_HOSTNAME | ||
int "Debug level hostname configuration" | ||
default 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we have "default 0" here (and "default 1" in other places). Default level should be ERROR (if not WARNING) consistently, to make sure that by default, errors don't go unnoticed by user.
And this is very well-known and well-discussed mistakes, which yet continues to happen - please don't pack too much stuff into one PR. I'm peering for half an hour into this, and don't understand much. Sure, after I'll peer into this for a couple hours more, I'll understand more than that, but why that should be required? |
Please rebase, this can't be applied to master to try it. |
I guess this needs more detailed explanation, mentioning CONFIG_NET_LOG_LEVEL_MAX and CONFIG_NET_LOG_LEVEL_DEFAULT, and with specific examples: before it was , now instead you do . |
subsys/net/lib/config/Kconfig
Outdated
default n | ||
default y if NET_LOG_GLOBAL | ||
config NET_LOG_LEVEL_CONFIG | ||
int "Debug level net config library" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be "Log level for net config library". Similarly in many other places.
@@ -131,6 +128,13 @@ void main(void) | |||
start_udp(); | |||
} | |||
|
|||
while (1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This of course can't be in the code ready for merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least following should be done:
- Rebase.
- Don't use values like 0,1,2,3,4, use symbolic logging levels instead.
- Debug logging help texts should look well in English.
Also ideally, converting to new logger should be split into different PR from switching to "snowflake" debug config. But my guess that's not possible (well, practical) at this stage.
P.S. As the new logger is an impeding doom, I'm all for getting over it, but we can't push sloppy conversion in just to get over it.
@jukkar regarding
Isn't it because LOG_LEVEL_... defines are in log.h file which must be included by C file because it utilizing defines? If so then I will move those defines to other file (something like log_types.h). |
Use new logging system with support for network log level. Signed-off-by: Jukka Rissanen <[email protected]>
Use new logging system with support for network log level. Signed-off-by: Jukka Rissanen <[email protected]>
Use new logging system with support for network log level. Signed-off-by: Jukka Rissanen <[email protected]>
Use new logging system with support for network log level. Signed-off-by: Jukka Rissanen <[email protected]>
Use new logging system with support for network log level. Signed-off-by: Jukka Rissanen <[email protected]>
Use new logging system with support for network log level. Signed-off-by: Jukka Rissanen <[email protected]>
Use new logging system with support for network log level. Signed-off-by: Jukka Rissanen <[email protected]>
Use new logging system with support for network log level. Signed-off-by: Jukka Rissanen <[email protected]>
Use new logging system with support for network log level. Signed-off-by: Jukka Rissanen <[email protected]>
Use new logging system with support for network log level. Signed-off-by: Jukka Rissanen <[email protected]>
Add "openthread" tag for sanitychecker when it is running OpenThread specific tests. This way it is easier to run just those few OpenThread specific tests. Signed-off-by: Jukka Rissanen <[email protected]>
Use new logging system with support for network log level. Signed-off-by: Jukka Rissanen <[email protected]>
Use new logging system with support for network log level. Signed-off-by: Jukka Rissanen <[email protected]>
One parameter was missing when calling net_hexdump_frags() which caused compile error. Signed-off-by: Jukka Rissanen <[email protected]>
Convert the USB networking to use the new logging system. Signed-off-by: Jukka Rissanen <[email protected]>
Use new logging system instead of SYS_LOG. Signed-off-by: Jukka Rissanen <[email protected]>
Use new logging system instead of SYS_LOG. Signed-off-by: Jukka Rissanen <[email protected]>
The code was trying to print peer IP address string but that pointer could contain garbage. There is actually no need to print anything in this case, the error code return is enough. Signed-off-by: Jukka Rissanen <[email protected]>
The application won't work anymore as it uses the old syslog logging and networking is now converted to use the new logger so there is no need for this sample application. Signed-off-by: Jukka Rissanen <[email protected]>
As the debugging print calls are async, all the strings that might be overwritten must use log_strdup() which will create a copy of the printable string. Signed-off-by: Jukka Rissanen <[email protected]>
|
ping @nordic-krch can you recheck and +1 if ok edit: fixed typos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jukkar i've been on sick leave thus the delay. looks ok.
No worries, thanks for the review! |
For reference, I don't see that being changed, e.g. not even where I made a comment on that https://github.com/zephyrproject-rtos/zephyr/pull/8816/files#r221893651 (but there're more occurrences). Let me submit a ticket to clarify the style we should use. |
This PR converts the CONFIG_NET_DEBUG_* and CONFIG_SYS_LOG_NET_LEVEL options to just simple CONFIG_NET_*_LOG_LEVEL setting. This enables user to have more fine grained debugging. The code uses the new logging subsystem for logging.