merge branch 'logging-refact' into nm-1-0

Backport some refactoring on the logging functions
from master.
This commit is contained in:
Thomas Haller 2015-04-29 15:17:27 +02:00
commit 90d39cea24
7 changed files with 41 additions and 27 deletions

View file

@ -57,7 +57,7 @@ G_STMT_START { \
if (nm_logging_enabled (_l, LOGD_DHCP)) { \
const char *_location = strrchr (file "", '/'); \
\
_nm_log (_location ? _location + 1 : file, line, func, _l, LOGD_DHCP, format, ## __VA_ARGS__); \
_nm_log_impl (_location ? _location + 1 : file, line, func, _l, LOGD_DHCP, 0, format, ## __VA_ARGS__); \
} \
} G_STMT_END

View file

@ -39,9 +39,9 @@
\
if ((self) != singleton_instance) \
g_snprintf (__prefix, sizeof (__prefix), "auth[%p]", (self)); \
nm_log ((level), (domain), \
"%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
__prefix _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
_nm_log ((level), (domain), 0, \
"%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
__prefix _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
} \
} G_STMT_END

View file

@ -76,9 +76,9 @@ static NMDefaultRouteManager *singleton_instance;
g_snprintf (__prefix, sizeof (__prefix), "default-route%c[%p]", __ch, (self)); \
else \
__prefix[STRLEN ("default-route")] = __ch; \
nm_log (__level, __domain, \
"%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
__prefix _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
_nm_log (__level, __domain, 0, \
"%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
__prefix _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
} \
} G_STMT_END

View file

@ -357,13 +357,14 @@ nm_logging_enabled (NMLogLevel level, NMLogDomain domain)
}
void
_nm_log (const char *file,
guint line,
const char *func,
NMLogLevel level,
NMLogDomain domain,
const char *fmt,
...)
_nm_log_impl (const char *file,
guint line,
const char *func,
NMLogLevel level,
NMLogDomain domain,
int error,
const char *fmt,
...)
{
va_list args;
char *msg;
@ -379,6 +380,10 @@ _nm_log (const char *file,
if (!(logging[level] & domain))
return;
/* Make sure that %m maps to the specified error */
if (error != 0)
errno = error;
va_start (args, fmt);
msg = g_strdup_vprintf (fmt, args);
va_end (args);

View file

@ -100,12 +100,20 @@ typedef enum { /*< skip >*/
#define nm_log_dbg(domain, ...) nm_log (LOGL_DEBUG, (domain), __VA_ARGS__)
#define nm_log_trace(domain, ...) nm_log (LOGL_TRACE, (domain), __VA_ARGS__)
/* A wrapper for the _nm_log_impl() function that adds call site information.
* Contrary to nm_log(), it unconditionally calls the function without
* checking whether logging for the given level and domain is enabled. */
#define _nm_log(level, domain, error, ...) \
G_STMT_START { \
_nm_log_impl (__FILE__, __LINE__, G_STRFUNC, (level), (domain), (error), ""__VA_ARGS__); \
} G_STMT_END
/* nm_log() only evaluates it's argument list after checking
* whether logging for the given level/domain is enabled. */
#define nm_log(level, domain, ...) \
G_STMT_START { \
if (nm_logging_enabled ((level), (domain))) { \
_nm_log (__FILE__, __LINE__, G_STRFUNC, (level), (domain), __VA_ARGS__); \
_nm_log (level, domain, 0, __VA_ARGS__); \
} \
} G_STMT_END
@ -136,13 +144,14 @@ typedef enum { /*< skip >*/
nm_log_ptr ((level), (domain), (self), __VA_ARGS__)
void _nm_log (const char *file,
guint line,
const char *func,
NMLogLevel level,
NMLogDomain domain,
const char *fmt,
...) __attribute__((__format__ (__printf__, 6, 7)));
void _nm_log_impl (const char *file,
guint line,
const char *func,
NMLogLevel level,
NMLogDomain domain,
int error,
const char *fmt,
...) __attribute__((__format__ (__printf__, 7, 8)));
const char *nm_logging_level_to_string (void);
const char *nm_logging_domains_to_string (void);

View file

@ -3630,7 +3630,7 @@ do_sleep_wake (NMManager *self, gboolean sleeping_changed)
waking_from_suspend = sleeping_changed && !priv->sleeping;
if (manager_sleeping (self)) {
nm_log_info (LOGD_SUSPEND, suspending ? "sleeping..." : "disabling...");
nm_log_info (LOGD_SUSPEND, "%s...", suspending ? "sleeping" : "disabling");
/* FIXME: are there still hardware devices that need to be disabled around
* suspend/resume?
@ -3648,7 +3648,7 @@ do_sleep_wake (NMManager *self, gboolean sleeping_changed)
nm_device_set_unmanaged (device, NM_UNMANAGED_INTERNAL, TRUE, NM_DEVICE_STATE_REASON_SLEEPING);
}
} else {
nm_log_info (LOGD_SUSPEND, waking_from_suspend ? "waking up..." : "re-enabling...");
nm_log_info (LOGD_SUSPEND, "%s...", waking_from_suspend ? "waking up" : "re-enabling");
if (waking_from_suspend) {
/* Belatedly take down Wake-on-LAN devices; ideally we wouldn't have to do this

View file

@ -63,7 +63,7 @@ read_connections (SCPluginIbft *self)
NMIbftConnection *connection;
if (!read_ibft_blocks ("/sbin/iscsiadm", &blocks, &error)) {
nm_log_dbg (LOGD_SETTINGS, _("ibft: failed to read iscsiadm records: %s"), error->message);
nm_log_dbg (LOGD_SETTINGS, "ibft: failed to read iscsiadm records: %s", error->message);
g_error_free (error);
return;
}
@ -71,13 +71,13 @@ read_connections (SCPluginIbft *self)
for (iter = blocks; iter; iter = iter->next) {
connection = nm_ibft_connection_new (iter->data, &error);
if (connection) {
nm_log_info (LOGD_SETTINGS, _("ibft: read connection '%s'"),
nm_log_info (LOGD_SETTINGS, "ibft: read connection '%s'",
nm_connection_get_id (NM_CONNECTION (connection)));
g_hash_table_insert (priv->connections,
g_strdup (nm_connection_get_uuid (NM_CONNECTION (connection))),
connection);
} else {
nm_log_warn (LOGD_SETTINGS, _("ibft: failed to read iscsiadm record: %s"), error->message);
nm_log_warn (LOGD_SETTINGS, "ibft: failed to read iscsiadm record: %s", error->message);
g_clear_error (&error);
}
}