core: move logging of monotonic-timestamp to "nm-logging.c"

This makes monotonic-timestamp handling independent of "nm-logging.c".
This commit is contained in:
Thomas Haller 2018-10-12 17:16:34 +02:00
parent 5ac0f3bbe7
commit 884ed15261
3 changed files with 26 additions and 11 deletions

View file

@ -1931,17 +1931,7 @@ monotonic_timestamp_get (struct timespec *tp)
monotonic_timestamp_offset_sec = (- ((gint64) tp->tv_sec)) + 1;
monotonic_timestamp_clock_mode = clock_mode;
if (nm_logging_enabled (LOGL_DEBUG, LOGD_CORE)) {
time_t now = time (NULL);
struct tm tm;
char s[255];
strftime (s, sizeof (s), "%Y-%m-%d %H:%M:%S", localtime_r (&now, &tm));
nm_log_dbg (LOGD_CORE, "monotonic timestamp started counting 1.%09ld seconds ago with "
"an offset of %lld.0 seconds to %s (local time is %s)",
tp->tv_nsec, (long long) -monotonic_timestamp_offset_sec,
clock_mode == 1 ? "CLOCK_BOOTTIME" : "CLOCK_MONOTONIC", s);
}
_nm_utils_monotonic_timestamp_initialized (tp, monotonic_timestamp_offset_sec, clock_mode == 1);
}
/**

View file

@ -253,6 +253,10 @@ nm_utils_get_monotonic_timestamp_ns_cached (gint64 *cache_now)
?: (*cache_now = nm_utils_get_monotonic_timestamp_ns ());
}
void _nm_utils_monotonic_timestamp_initialized (const struct timespec *tp,
gint64 offset_sec,
gboolean is_boottime);
gboolean nm_utils_is_valid_path_component (const char *name);
const char *NM_ASSERT_VALID_PATH_COMPONENT (const char *name);

View file

@ -744,6 +744,27 @@ _nm_log_impl (const char *file,
/*****************************************************************************/
void
_nm_utils_monotonic_timestamp_initialized (const struct timespec *tp,
gint64 offset_sec,
gboolean is_boottime)
{
if (nm_logging_enabled (LOGL_DEBUG, LOGD_CORE)) {
time_t now = time (NULL);
struct tm tm;
char s[255];
strftime (s, sizeof (s), "%Y-%m-%d %H:%M:%S", localtime_r (&now, &tm));
nm_log_dbg (LOGD_CORE, "monotonic timestamp started counting 1.%09ld seconds ago with "
"an offset of %lld.0 seconds to %s (local time is %s)",
tp->tv_nsec,
(long long) -offset_sec,
is_boottime ? "CLOCK_BOOTTIME" : "CLOCK_MONOTONIC", s);
}
}
/*****************************************************************************/
static void
nm_log_handler (const char *log_domain,
GLogLevelFlags level,