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

Log levels implementation #477

Closed
wants to merge 11 commits into from
Closed

Conversation

jrybar-rh
Copy link
Member

Summary

There was a request to being able to log every loaded .rules script. This required a change in the logging function and a new option parsed during the start of the polkit service.

Detailed description and/or reproducer

All the calls of the logging function had to be changed accordingly. The levels chosen for each such call were guessed from the message -> there might be discussions about that.
The default log level is set to "notify" in the input unit file, this equals the original logging behaviour of polkit. The default and backup value in code is set to "errors only". The "default default" logging shall be "quiet", not too "verbose", but this is always subjective.
A log message about every loaded rule file can be activated by editting the unit file and setting the log level to 3.

@@ -52,6 +52,14 @@ struct _PolkitBackendAuthority
GObject parent_instance;
};

enum
{
LOG_LEVEL_ERROR, // log errors only
Copy link
Member

Choose a reason for hiding this comment

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

Even if other levels are not used, please add support for all syslog levels, so that we can add LogControl1 support later: https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.LogControl1.html (I can wire that up once this is merged)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the exact same levels as in syslog should be used. This is because those priorities will be propagated to the entries in the journal, and ideally there is a clear mapping between what is visible here in the code and what the journal allows. Doing a 1:1 mapping is the most reasonable.

Copy link
Contributor

@keszybz keszybz left a comment

Choose a reason for hiding this comment

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

It's not clear to me if those log levels are propagated to the journal. If they are not, they should be.

ExecStart=@libprivdir@/polkitd --no-debug
ExecStart=@libprivdir@/polkitd --no-debug --log-level=2
Copy link
Contributor

Choose a reason for hiding this comment

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

Does --no-debug still make sense if --log-level is specified?

Copy link
Member Author

Choose a reason for hiding this comment

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

I asked myself the same question and it seems that it still does make sense, because it reroutes the output from stdout and stderr to /dev/null and that AFAIK affects Glib's library messages too.

void
polkit_backend_authority_set_log_level (const gint level)
{
if ((level >= 0) && (level <= LOG_LEVEL_VERBOSE))
Copy link
Contributor

Choose a reason for hiding this comment

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

Boolean operators have lower precedence than comparison operators, so those nested parens are not needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you're right, but it's clearer to the reader and immediately visible. That's one of the "will do more than I have to just to make it prettier for humans" LifeProTips on my list :D

@@ -52,6 +52,14 @@ struct _PolkitBackendAuthority
GObject parent_instance;
};

enum
{
LOG_LEVEL_ERROR, // log errors only
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the exact same levels as in syslog should be used. This is because those priorities will be propagated to the entries in the journal, and ideally there is a clear mapping between what is visible here in the code and what the journal allows. Doing a 1:1 mapping is the most reasonable.

Comment on lines 45 to 46
{"log-level", 'l', 0, G_OPTION_ARG_INT, &opt_log_level, "Set a level of logging. Values (0-3): errors, warnings, notifications, verbose.",
"[0,1,2,3]"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yeah, especially numerical values different than syslog would be really confusing. Please don't do this. And names too. Please just reuse the standard values.

This should mitigate the confusion for the user and enable future
integration with journal and LogControl.
@jrybar-rh jrybar-rh requested review from keszybz and bluca August 6, 2024 08:37
@@ -8,7 +8,7 @@ BusName=org.freedesktop.PolicyKit1
CapabilityBoundingSet=CAP_SETUID CAP_SETGID
DeviceAllow=/dev/null rw
DevicePolicy=strict
ExecStart=@libprivdir@/polkitd --no-debug
ExecStart=@libprivdir@/polkitd --no-debug --log-level=5
Copy link
Member

Choose a reason for hiding this comment

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

The command line parameter should take string representations, rather than numbers, as it would be really confusing to use otherwise

Copy link
Member Author

@jrybar-rh jrybar-rh Aug 6, 2024

Choose a reason for hiding this comment

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

Yes, planned after release (that I need to make this week asap).

as it would be really confusing to use otherwise

polkitd binary is not supposed to be run by user and the help info mentions the correct values. I guess admins would figure out.

Copy link
Member

Choose a reason for hiding this comment

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

It should be trivial to add? I think it would be better to fix this before the release. Admins adding a drop-in to change the default log level are the users, and it's not really nice to use numeric values like this

Copy link
Member Author

Choose a reason for hiding this comment

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

It is a glib option that would probably require a callback function. I'm almost sure the result will be a few lines of code, but I've never done that and I'd have to research the docs and stuff and I really need to make that release instead.

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't need a callback, I'll prep a PR based on this and open it, probably tomorrow, including LogControl support. I'd really like to ahve both in the next release, so they can be in Debian 13

Copy link
Member

Choose a reason for hiding this comment

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

Here it is: #482

The commits from this PR are squashed in the first one. The difference is using strings instead of numbers for the command line argument, and also passing the log level to the syslog() call so that messages are tagged accordingly to priority in the journal. And then another commit to add LogControl1 on top of that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I implemented it with a short callback yesterday. I just didn't push it, for I didn't consider this a race.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, I had presumed that implementing it with tools provided by Glib would allow having the options auto-documented in help page and/or auto-translated. Like I said, it required going through the documentation that showed that it probably doesn't cover the case of this PR (maybe I'm wrong about this, a Glib expert could know more).

@jrybar-rh
Copy link
Member Author

Merged in #482 along with LogControl support.

@jrybar-rh jrybar-rh closed this Aug 7, 2024
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