mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-08 11:50:22 +01:00
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
This commit is contained in:
parent
3ea9169c81
commit
e62aa4165f
3 changed files with 11 additions and 9 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 ();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue