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
13 changes: 13 additions & 0 deletions src/polkitbackend/polkitbackendauthority.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum
};

static guint signals[LAST_SIGNAL] = {0};
static guint polkit_authority_log_level = LOG_LEVEL_ERROR;

G_DEFINE_ABSTRACT_TYPE (PolkitBackendAuthority, polkit_backend_authority, G_TYPE_OBJECT);

Expand Down Expand Up @@ -1561,6 +1562,7 @@ _color_get (_Color color)

void
polkit_backend_authority_log (PolkitBackendAuthority *authority,
const guint message_log_level,
const gchar *format,
...)
{
Expand All @@ -1571,6 +1573,8 @@ polkit_backend_authority_log (PolkitBackendAuthority *authority,
gchar *message;
va_list var_args;


g_return_if_fail (message_log_level <= polkit_authority_log_level);
g_return_if_fail (POLKIT_BACKEND_IS_AUTHORITY (authority));

va_start (var_args, format);
Expand All @@ -1591,3 +1595,12 @@ polkit_backend_authority_log (PolkitBackendAuthority *authority,

g_free (message);
}

void
polkit_backend_authority_set_log_level (const guint level)
{
if (level <= LOG_LEVEL_VERBOSE)
{
polkit_authority_log_level = level;
}
}
8 changes: 8 additions & 0 deletions src/polkitbackend/polkitbackendauthority.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

LOG_LEVEL_WARNING, // errors and warnings
LOG_LEVEL_NOTIFY, // like "all" interesting
LOG_LEVEL_VERBOSE // log every heartbeat, cough and fallen leaf. This is unlikely, but for future's sake...
};

/**
* PolkitBackendAuthorityClass:
* @parent_class: The parent class.
Expand Down