Skip to content
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

Fixing code location log level filtering #1753

Merged
merged 1 commit into from
Dec 23, 2020

Conversation

aquesnel
Copy link
Contributor

As part of the logging refactoring in #1708 I broke the code location based log level filtering. This pull request fixes the code location log level filtering.

Copy link
Member

@matt335672 matt335672 left a comment

Choose a reason for hiding this comment

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

Some minor comments

common/log.c Outdated
Comment on lines 535 to 543
return (g_staticLogConfig->fd >= 0
&& (override_destination_level || log_level <= g_staticLogConfig->log_level))
&& ((override_destination_level && log_level <= override_log_level)
|| (!override_destination_level && log_level <= g_staticLogConfig->log_level)))
|| (g_staticLogConfig->enable_syslog
&& (override_destination_level || log_level <= g_staticLogConfig->syslog_level))
&& ((override_destination_level && log_level <= override_log_level)
|| (!override_destination_level && log_level <= g_staticLogConfig->syslog_level)))
|| (g_staticLogConfig->enable_console
&& (override_destination_level || log_level <= g_staticLogConfig->console_level));
&& ((override_destination_level && log_level <= override_log_level)
|| (!override_destination_level && log_level <= g_staticLogConfig->console_level)));
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little concerned with this mega-conditional. It's quite hard to parse mentally (at least it is for me), and there's some repetition in it. Maybe split it up a bit? Here's a suggestion:-

{
    bool_t result;
    /* Is log initialized? */
    if (g_staticLogConfig == NULL)
    {
        result = 0;
    }
    else if (override_destination_level)
    {
        /* Override in place - if the message should be logged, is any
         * destination enabled? */
        if (log_level > override_log_level)
        {
            result = 0;
        }
        else
        {
            result =
                g_staticLogConfig->fd >= 0 ||
                g_staticLogConfig->enable_syslog ||
                g_staticLogConfig->enable_console;
        }
    }
    else
    {
        /* Is there at least one log destination which will accept the
         * message based on the log level? */
        result =
            (g_staticLogConfig->fd >= 0 &&
             log_level <= g_staticLogConfig->log_level) ||
            (g_staticLogConfig->enable_syslog &&
             log_level <= g_staticLogConfig->syslog_level) ||
            (g_staticLogConfig->enable_console &&
             log_level <= g_staticLogConfig->console_level);
    }

    return result;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cleaned up to be easier to understand.

@aquesnel aquesnel requested a review from matt335672 December 19, 2020 16:24
@aquesnel
Copy link
Contributor Author

@matt335672 I've implemented the changes you suggested.

Please let me know if more changes are needed before merging.

@metalefty
Copy link
Member

Is this should be in v0.9.15?

@aquesnel
Copy link
Contributor Author

@metalefty Yes I think this pull request should be in v0.9.15 because the log filtering by source location in devel is broken without this pull request.

@metalefty metalefty added this to the v0.9.15 milestone Dec 21, 2020
/* all logging outputs are disabled */
return 0;
}
else if (override_destination_level)
Copy link
Member

Choose a reason for hiding this comment

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

I'm happy with either multiple returns in a function, or if / else if with a single return at the end. Here you've mixed styles somewhat. It'll work fine, but I think there's a chance that in the future a static analysis will moan about an unreachable 'else' branch following a return.

I'd suggest either removing the unnecessary else statements, or using a single return - whatever seems more natural to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@matt335672 I've implemented this feedback using multiple returns by only have a single level of nesting for the if/else. Please let me know if I correctly interpreted your feedback, or if you'd prefer that I use the single return at the end style.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry - I've probably not been very clear.

My point was that in this kind of construction:-

if (<something>)
{
    return 1;
}
else if (<something else>)
...

the else in bold is superfluous and not required. At some stage I'd expect a static analysis tool to say something about it. Does that make more sense?

The nesting style you use, or whether you use a single return or multiple returns is completely up to you. I've got my own preferences but they're not relevant at all.

@aquesnel aquesnel force-pushed the fix_location_logging branch from 3c6bb96 to 983c938 Compare December 23, 2020 02:57
@aquesnel aquesnel force-pushed the fix_location_logging branch from 983c938 to a4f3471 Compare December 23, 2020 04:02
@aquesnel
Copy link
Contributor Author

CR feedback implemented, branch squashed and rebased to devel.

This should be ready to merge once @matt335672 reviews the changes.

@metalefty metalefty merged commit a033cf0 into neutrinolabs:devel Dec 23, 2020
@aquesnel aquesnel deleted the fix_location_logging branch December 28, 2020 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants