summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-12-17 09:30:35 +0100
committerThomas Haller <thaller@redhat.com>2014-12-18 17:38:35 +0100
commitca399f00c411f526d87681a196ec2002c31b3032 (patch)
tree8dda36c558548b7e8ddafe99506e4aa4d04c50e3
parent31317fcf3275c04f91ca33864b23955d1b7ce108 (diff)
downloadNetworkManager-ca399f00c411f526d87681a196ec2002c31b3032.tar.gz
logging: pass file:line as separate arguments to _nm_log()
Previously, we would only pass one argument @loc to _nm_log() which was set to G_STRLOC. That has the disadvantage, that for every logging line the binary contains an individual string __FILE__:__LINE__. By splitting up @loc into @file and @line, we reduce the number of strings in the NetworkManager binary by about 50k. https://bugzilla.gnome.org/show_bug.cgi?id=741651 (cherry picked from commit e62aa4165f79a1b42a3c19258284bb945cdaf148)
-rw-r--r--src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h4
-rw-r--r--src/nm-logging.c9
-rw-r--r--src/nm-logging.h7
3 files changed, 11 insertions, 9 deletions
diff --git a/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h b/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h
index 5bd1f81f8b..ce1716b175 100644
--- a/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h
+++ b/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h
@@ -55,9 +55,9 @@ _slog_level_to_nm (int slevel)
G_STMT_START { \
guint32 _l = _slog_level_to_nm ((level)); \
if (nm_logging_enabled (_l, LOGD_DHCP)) { \
- const char *_location = strrchr ((file ":" G_STRINGIFY(line)), '/'); \
+ const char *_location = strrchr (file "", '/'); \
\
- _nm_log (_location ? _location + 1 : (file ":" G_STRINGIFY(line)), func, _l, LOGD_DHCP, format, ## __VA_ARGS__); \
+ _nm_log (_location ? _location + 1 : file, line, func, _l, LOGD_DHCP, format, ## __VA_ARGS__); \
} \
} G_STMT_END
diff --git a/src/nm-logging.c b/src/nm-logging.c
index c32c2d364a..f1291fa73b 100644
--- a/src/nm-logging.c
+++ b/src/nm-logging.c
@@ -357,7 +357,8 @@ nm_logging_enabled (NMLogLevel level, NMLogDomain domain)
}
void
-_nm_log (const char *loc,
+_nm_log (const char *file,
+ guint line,
const char *func,
NMLogLevel level,
NMLogDomain domain,
@@ -387,13 +388,13 @@ _nm_log (const char *loc,
g_get_current_time (&tv);
syslog_level = LOG_DEBUG;
g_log_level = G_LOG_LEVEL_DEBUG;
- fullmsg = g_strdup_printf ("<trace> [%ld.%06ld] [%s] %s(): %s", tv.tv_sec, tv.tv_usec, loc, func, msg);
+ fullmsg = g_strdup_printf ("<trace> [%ld.%06ld] [%s:%u] %s(): %s", tv.tv_sec, tv.tv_usec, file, line, func, msg);
break;
case LOGL_DEBUG:
g_get_current_time (&tv);
syslog_level = LOG_INFO;
g_log_level = G_LOG_LEVEL_DEBUG;
- fullmsg = g_strdup_printf ("<debug> [%ld.%06ld] [%s] %s(): %s", tv.tv_sec, tv.tv_usec, loc, func, msg);
+ fullmsg = g_strdup_printf ("<debug> [%ld.%06ld] [%s:%u] %s(): %s", tv.tv_sec, tv.tv_usec, file, line, func, msg);
break;
case LOGL_INFO:
syslog_level = LOG_INFO;
@@ -410,7 +411,7 @@ _nm_log (const char *loc,
/* g_log_level is still WARNING, because ERROR is fatal */
g_log_level = G_LOG_LEVEL_WARNING;
g_get_current_time (&tv);
- fullmsg = g_strdup_printf ("<error> [%ld.%06ld] [%s] %s(): %s", tv.tv_sec, tv.tv_usec, loc, func, msg);
+ fullmsg = g_strdup_printf ("<error> [%ld.%06ld] [%s:%u] %s(): %s", tv.tv_sec, tv.tv_usec, file, line, func, msg);
break;
default:
g_assert_not_reached ();
diff --git a/src/nm-logging.h b/src/nm-logging.h
index 60ddb1e511..4ab2db3ad5 100644
--- a/src/nm-logging.h
+++ b/src/nm-logging.h
@@ -105,7 +105,7 @@ typedef enum { /*< skip >*/
#define nm_log(level, domain, ...) \
G_STMT_START { \
if (nm_logging_enabled ((level), (domain))) { \
- _nm_log (G_STRLOC, G_STRFUNC, (level), (domain), __VA_ARGS__); \
+ _nm_log (__FILE__, __LINE__, G_STRFUNC, (level), (domain), __VA_ARGS__); \
} \
} G_STMT_END
@@ -134,12 +134,13 @@ typedef enum { /*< skip >*/
nm_log_ptr ((level), (domain), (self), __VA_ARGS__)
-void _nm_log (const char *loc,
+void _nm_log (const char *file,
+ guint line,
const char *func,
NMLogLevel level,
NMLogDomain domain,
const char *fmt,
- ...) __attribute__((__format__ (__printf__, 5, 6)));
+ ...) __attribute__((__format__ (__printf__, 6, 7)));
const char *nm_logging_level_to_string (void);
const char *nm_logging_domains_to_string (void);