-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
RFC: ospf6d: add conditional debug log macro #15722
RFC: ospf6d: add conditional debug log macro #15722
Conversation
I've marked this PR as a draft, because I expect the change may be controversial. I opted not to try a blanket replacement across the codebase, because I've only just started working on FRR (specifically only in the ospf6d area) and will be learning the maintainers' expectations and tolerance for code churn. Nevertheless, I'm developing a sense that the ospf6d code base is not receiving a great deal of development focus at the moment, and there are a number of general maintenance issues I need to work through towards my goal of adding support for RFC8632 (OSPFv3 Link State Advertisement (LSA) Extensibility). Please view this PR as an introduction of sorts and an opportunity to tell me about the kind of change that is or isn't likely to be acceptable 'upstream'. Thanks! |
a78a7be
to
018e0ae
Compare
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.
Before moving on, can zlog.h be split into a separate commit?
lib/zlog.h
Outdated
@@ -115,6 +115,12 @@ static inline void zlog_ref(const struct xref_logmsg *xref, | |||
#define zlog_notice(...) _zlog_ecref(0, LOG_NOTICE, __VA_ARGS__) | |||
#define zlog_debug(...) _zlog_ecref(0, LOG_DEBUG, __VA_ARGS__) | |||
|
|||
#define zlog_debug_if(condition, ...) \ |
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 have similar (not for logging) COND_FLAG()
macro, thinking loudly just if we could you the same naming instead? zlog_debug_cond()
. Another example bgp_cond_adv_debug()
(same cond naming)
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've changed zlog_debug_if()
to zlog_debug_cond()
as suggested.
I think a shorter macro name would be better, given how often it's used and how big an impact it has on line wrapping, but consistency with established convention probably takes precedence.
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 a shorter macro name would be better,
Indeed this is repeating the development of 12272. It started at zlog_debugif()
, went to zlog_dbgif()
and finally arrived at dbg()
018e0ae
to
6fcf32d
Compare
6fcf32d
to
027190c
Compare
@donaldsharp Apologies, I accidentally closed PR #15721 (trying to avoid embarrassment) and couldn't reopen it and unfortunately that caused some confusion and resulted in your comment almost getting missed. The comment was: Thanks for pointing out the other work - I was unaware. After looking at these PRs, my understanding of their primary intents are as follows: #15522 - adds additional uses of the #15646 - modifies the debug library, but it's not apparent to me what the calling API and usage patterns are. It isn't currently used by ospf6d and doesn't appear to offer a replacement for the So merging any of those PRs would not address the kind of issue that this PR is trying to address, namely that there is a commonly used pattern for debug logging, which (imho as a new reader) could be improved to aid readability. |
Introduces a new logging macro: zlog_debug_cond(condition, message) It can replace a repeating pattern: if (condition) zlog_debug(...) becomes: zlog_debug_cond(condition, ...) Code readability can be improved when debug logging reads like statements. It is meant to be used without side effects in the evaluation of the condition or format string. Signed-off-by: Andrew Cooks <acooks.at.bda@gmail.com>
Uses the new zlog_debug_cond(condition, message) macro to replace this pattern: if (condition) zlog_debug(...) with this: zlog_debug_cond(condition, ...) Signed-off-by: Andrew Cooks <acooks.at.bda@gmail.com>
027190c
to
1d459f7
Compare
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.
NAK as commented
btw, the target pattern with #12272 is
It was previously discussed that this changeover will happen separately and 12272 is only going to add the new mechanism. ⇒ changeover can be done in smaller blocks |
The approach of only allowing defined flag names is the major point of difference. It will be a much bigger change around the existing debug log call sites where conditions are used. It would be nice to see some WIP for how those conversions can be done. However, I understand that there is a clear vision for the end state for the debug logging, and don't wish to distract from that, therefore this PR can probably close. Thanks for the review comments! |
Introduces a new logging macro: zlog_debug_cond(condition, message) and uses it to replace a repeating pattern:
becomes:
Code readability is improved when debug logging reads like statements. It is meant to be used without side effects in the format string evaluation.