logging: merge branch 'th/logging-inline-enabled'
This commit is contained in:
@@ -98,10 +98,15 @@ typedef struct {
|
|||||||
LogFormatFlags log_format_level;
|
LogFormatFlags log_format_level;
|
||||||
} LogLevelDesc;
|
} LogLevelDesc;
|
||||||
|
|
||||||
|
NMLogDomain _nm_logging_enabled_state[_LOGL_N_REAL] = {
|
||||||
|
/* nm_logging_setup ("INFO", LOGD_DEFAULT_STRING, NULL, NULL); */
|
||||||
|
[LOGL_INFO] = LOGD_DEFAULT,
|
||||||
|
[LOGL_WARN] = LOGD_DEFAULT,
|
||||||
|
[LOGL_ERR] = LOGD_DEFAULT,
|
||||||
|
};
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
NMLogLevel log_level;
|
NMLogLevel log_level;
|
||||||
NMLogDomain logging[_LOGL_N_REAL];
|
|
||||||
gboolean logging_set_up;
|
|
||||||
LogFormatFlags log_format_flags;
|
LogFormatFlags log_format_flags;
|
||||||
enum {
|
enum {
|
||||||
LOG_BACKEND_GLIB,
|
LOG_BACKEND_GLIB,
|
||||||
@@ -116,6 +121,7 @@ static struct {
|
|||||||
* but that feature doesn't seem well supported. */
|
* but that feature doesn't seem well supported. */
|
||||||
const LogDesc domain_desc[_DOMAIN_DESC_LEN];
|
const LogDesc domain_desc[_DOMAIN_DESC_LEN];
|
||||||
} global = {
|
} global = {
|
||||||
|
/* nm_logging_setup ("INFO", LOGD_DEFAULT_STRING, NULL, NULL); */
|
||||||
.log_level = LOGL_INFO,
|
.log_level = LOGL_INFO,
|
||||||
.log_backend = LOG_BACKEND_GLIB,
|
.log_backend = LOG_BACKEND_GLIB,
|
||||||
.log_format_flags = _LOG_FORMAT_FLAG_DEFAULT,
|
.log_format_flags = _LOG_FORMAT_FLAG_DEFAULT,
|
||||||
@@ -185,19 +191,6 @@ static char *_domains_to_string (gboolean include_level_override);
|
|||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
static void
|
|
||||||
_ensure_initialized (void)
|
|
||||||
{
|
|
||||||
if (G_UNLIKELY (!global.logging_set_up)) {
|
|
||||||
int errsv = errno;
|
|
||||||
|
|
||||||
nm_logging_setup ("INFO", LOGD_DEFAULT_STRING, NULL, NULL);
|
|
||||||
|
|
||||||
/* must ensure that errno is not modified. */
|
|
||||||
errno = errsv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
match_log_level (const char *level,
|
match_log_level (const char *level,
|
||||||
NMLogLevel *out_level,
|
NMLogLevel *out_level,
|
||||||
@@ -224,7 +217,7 @@ nm_logging_setup (const char *level,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GString *unrecognized = NULL;
|
GString *unrecognized = NULL;
|
||||||
NMLogDomain new_logging[G_N_ELEMENTS (global.logging)];
|
NMLogDomain new_logging[G_N_ELEMENTS (_nm_logging_enabled_state)];
|
||||||
NMLogLevel new_log_level = global.log_level;
|
NMLogLevel new_log_level = global.log_level;
|
||||||
char **tmp, **iter;
|
char **tmp, **iter;
|
||||||
int i;
|
int i;
|
||||||
@@ -235,13 +228,8 @@ nm_logging_setup (const char *level,
|
|||||||
g_return_val_if_fail (!error || !*error, FALSE);
|
g_return_val_if_fail (!error || !*error, FALSE);
|
||||||
|
|
||||||
/* domains */
|
/* domains */
|
||||||
if (!domains || !*domains) {
|
if (!domains || !*domains)
|
||||||
domains = global.logging_set_up
|
domains = (domains_free = _domains_to_string (FALSE));
|
||||||
? (domains_free = _domains_to_string (FALSE))
|
|
||||||
: LOGD_DEFAULT_STRING;
|
|
||||||
}
|
|
||||||
|
|
||||||
global.logging_set_up = TRUE;
|
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
||||||
new_logging[i] = 0;
|
new_logging[i] = 0;
|
||||||
@@ -253,7 +241,7 @@ nm_logging_setup (const char *level,
|
|||||||
if (new_log_level == _LOGL_KEEP) {
|
if (new_log_level == _LOGL_KEEP) {
|
||||||
new_log_level = global.log_level;
|
new_log_level = global.log_level;
|
||||||
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
||||||
new_logging[i] = global.logging[i];
|
new_logging[i] = _nm_logging_enabled_state[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,7 +309,7 @@ nm_logging_setup (const char *level,
|
|||||||
|
|
||||||
if (domain_log_level == _LOGL_KEEP) {
|
if (domain_log_level == _LOGL_KEEP) {
|
||||||
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
||||||
new_logging[i] = (new_logging[i] & ~bits) | (global.logging[i] & bits);
|
new_logging[i] = (new_logging[i] & ~bits) | (_nm_logging_enabled_state[i] & bits);
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < G_N_ELEMENTS (new_logging); i++) {
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++) {
|
||||||
if (i < domain_log_level)
|
if (i < domain_log_level)
|
||||||
@@ -339,7 +327,7 @@ nm_logging_setup (const char *level,
|
|||||||
|
|
||||||
global.log_level = new_log_level;
|
global.log_level = new_log_level;
|
||||||
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
||||||
global.logging[i] = new_logging[i];
|
_nm_logging_enabled_state[i] = new_logging[i];
|
||||||
|
|
||||||
if ( had_platform_debug
|
if ( had_platform_debug
|
||||||
&& _nm_logging_clear_platform_logging_cache
|
&& _nm_logging_clear_platform_logging_cache
|
||||||
@@ -384,8 +372,6 @@ nm_logging_all_levels_to_string (void)
|
|||||||
const char *
|
const char *
|
||||||
nm_logging_domains_to_string (void)
|
nm_logging_domains_to_string (void)
|
||||||
{
|
{
|
||||||
_ensure_initialized ();
|
|
||||||
|
|
||||||
if (G_UNLIKELY (!global.logging_domains_to_string))
|
if (G_UNLIKELY (!global.logging_domains_to_string))
|
||||||
global.logging_domains_to_string = _domains_to_string (TRUE);
|
global.logging_domains_to_string = _domains_to_string (TRUE);
|
||||||
|
|
||||||
@@ -406,7 +392,7 @@ _domains_to_string (gboolean include_level_override)
|
|||||||
str = g_string_sized_new (75);
|
str = g_string_sized_new (75);
|
||||||
for (diter = &global.domain_desc[0]; diter->name; diter++) {
|
for (diter = &global.domain_desc[0]; diter->name; diter++) {
|
||||||
/* If it's set for any lower level, it will also be set for LOGL_ERR */
|
/* If it's set for any lower level, it will also be set for LOGL_ERR */
|
||||||
if (!(diter->num & global.logging[LOGL_ERR]))
|
if (!(diter->num & _nm_logging_enabled_state[LOGL_ERR]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (str->len)
|
if (str->len)
|
||||||
@@ -418,15 +404,15 @@ _domains_to_string (gboolean include_level_override)
|
|||||||
|
|
||||||
/* Check if it's logging at a lower level than the default. */
|
/* Check if it's logging at a lower level than the default. */
|
||||||
for (i = 0; i < global.log_level; i++) {
|
for (i = 0; i < global.log_level; i++) {
|
||||||
if (diter->num & global.logging[i]) {
|
if (diter->num & _nm_logging_enabled_state[i]) {
|
||||||
g_string_append_printf (str, ":%s", global.level_desc[i].name);
|
g_string_append_printf (str, ":%s", global.level_desc[i].name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Check if it's logging at a higher level than the default. */
|
/* Check if it's logging at a higher level than the default. */
|
||||||
if (!(diter->num & global.logging[global.log_level])) {
|
if (!(diter->num & _nm_logging_enabled_state[global.log_level])) {
|
||||||
for (i = global.log_level + 1; i < G_N_ELEMENTS (global.logging); i++) {
|
for (i = global.log_level + 1; i < G_N_ELEMENTS (_nm_logging_enabled_state); i++) {
|
||||||
if (diter->num & global.logging[i]) {
|
if (diter->num & _nm_logging_enabled_state[i]) {
|
||||||
g_string_append_printf (str, ":%s", global.level_desc[i].name);
|
g_string_append_printf (str, ":%s", global.level_desc[i].name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -459,18 +445,6 @@ nm_logging_all_domains_to_string (void)
|
|||||||
return str->str;
|
return str->str;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
nm_logging_enabled (NMLogLevel level, NMLogDomain domain)
|
|
||||||
{
|
|
||||||
if ((guint) level >= G_N_ELEMENTS (global.logging))
|
|
||||||
g_return_val_if_reached (FALSE);
|
|
||||||
|
|
||||||
/* This function is guaranteed not to modify errno. */
|
|
||||||
_ensure_initialized ();
|
|
||||||
|
|
||||||
return !!(global.logging[level] & domain);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if SYSTEMD_JOURNAL
|
#if SYSTEMD_JOURNAL
|
||||||
__attribute__((__format__ (__printf__, 4, 5)))
|
__attribute__((__format__ (__printf__, 4, 5)))
|
||||||
static void
|
static void
|
||||||
@@ -515,12 +489,10 @@ _nm_log_impl (const char *file,
|
|||||||
char s_buf_location[1024];
|
char s_buf_location[1024];
|
||||||
GTimeVal tv;
|
GTimeVal tv;
|
||||||
|
|
||||||
if ((guint) level >= G_N_ELEMENTS (global.logging))
|
if ((guint) level >= G_N_ELEMENTS (_nm_logging_enabled_state))
|
||||||
g_return_if_reached ();
|
g_return_if_reached ();
|
||||||
|
|
||||||
_ensure_initialized ();
|
if (!(_nm_logging_enabled_state[level] & domain))
|
||||||
|
|
||||||
if (!(global.logging[level] & domain))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Make sure that %m maps to the specified error */
|
/* Make sure that %m maps to the specified error */
|
||||||
@@ -609,7 +581,7 @@ _nm_log_impl (const char *file,
|
|||||||
const char *s_domain_1 = NULL;
|
const char *s_domain_1 = NULL;
|
||||||
GString *s_domain_all = NULL;
|
GString *s_domain_all = NULL;
|
||||||
NMLogDomain dom_all = domain;
|
NMLogDomain dom_all = domain;
|
||||||
NMLogDomain dom = dom_all & global.logging[level];
|
NMLogDomain dom = dom_all & _nm_logging_enabled_state[level];
|
||||||
|
|
||||||
for (diter = &global.domain_desc[0]; diter->name; diter++) {
|
for (diter = &global.domain_desc[0]; diter->name; diter++) {
|
||||||
if (!NM_FLAGS_HAS (dom_all, diter->num))
|
if (!NM_FLAGS_HAS (dom_all, diter->num))
|
||||||
|
@@ -158,7 +158,14 @@ void _nm_log_impl (const char *file,
|
|||||||
|
|
||||||
const char *nm_logging_level_to_string (void);
|
const char *nm_logging_level_to_string (void);
|
||||||
const char *nm_logging_domains_to_string (void);
|
const char *nm_logging_domains_to_string (void);
|
||||||
gboolean nm_logging_enabled (NMLogLevel level, NMLogDomain domain);
|
|
||||||
|
extern NMLogDomain _nm_logging_enabled_state[_LOGL_N_REAL];
|
||||||
|
static inline gboolean
|
||||||
|
nm_logging_enabled (NMLogLevel level, NMLogDomain domain)
|
||||||
|
{
|
||||||
|
nm_assert (((guint) level) < G_N_ELEMENTS (_nm_logging_enabled_state));
|
||||||
|
return !!(_nm_logging_enabled_state[level] & domain);
|
||||||
|
}
|
||||||
|
|
||||||
const char *nm_logging_all_levels_to_string (void);
|
const char *nm_logging_all_levels_to_string (void);
|
||||||
const char *nm_logging_all_domains_to_string (void);
|
const char *nm_logging_all_domains_to_string (void);
|
||||||
|
Reference in New Issue
Block a user