mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-13 07:00:32 +01:00
cloud-setup,glib-aux: merge branch 'th/cloud-setup-logging'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/937
This commit is contained in:
commit
faf315148b
5 changed files with 81 additions and 78 deletions
|
|
@ -5172,6 +5172,7 @@ src_nm_cloud_setup_nm_cloud_setup_LDADD = \
|
|||
src/libnm-core-aux-intern/libnm-core-aux-intern.la \
|
||||
src/libnm-base/libnm-base.la \
|
||||
src/libnm-glib-aux/libnm-glib-aux.la \
|
||||
src/libnm-log-null/libnm-log-null.la \
|
||||
src/libnm-std-aux/libnm-std-aux.la \
|
||||
src/c-siphash/libc-siphash.la \
|
||||
src/libnm-client-impl/libnm.la \
|
||||
|
|
@ -5236,6 +5237,7 @@ src_nm_cloud_setup_tests_test_cloud_setup_general_LDADD = \
|
|||
src/libnm-core-aux-intern/libnm-core-aux-intern.la \
|
||||
src/libnm-base/libnm-base.la \
|
||||
src/libnm-glib-aux/libnm-glib-aux.la \
|
||||
src/libnm-log-null/libnm-log-null.la \
|
||||
src/libnm-std-aux/libnm-std-aux.la \
|
||||
src/c-siphash/libc-siphash.la \
|
||||
src/libnm-client-impl/libnm.la \
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include <syslog.h>
|
||||
|
||||
#include "nm-time-utils.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
const LogLevelDesc nm_log_level_desc[_LOGL_N] = {
|
||||
|
|
@ -77,3 +79,61 @@ _nm_log_parse_level(const char *level, NMLogLevel *out_level)
|
|||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
volatile NMLogLevel _nm_logging_enabled_value = LOGL_TRACE;
|
||||
|
||||
void
|
||||
_nm_logging_enabled_init(const char *level_str)
|
||||
{
|
||||
NMLogLevel level;
|
||||
|
||||
if (!_nm_log_parse_level(level_str, &level))
|
||||
level = LOGL_WARN;
|
||||
else if (level == _LOGL_KEEP)
|
||||
level = LOGL_WARN;
|
||||
|
||||
_nm_logging_enabled_value = level;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
_nm_log_simple_printf(NMLogLevel level, const char *fmt, ...)
|
||||
{
|
||||
gs_free char *msg_heap = NULL;
|
||||
char msg_stack[700];
|
||||
const char * msg;
|
||||
const char * level_str;
|
||||
gint64 ts;
|
||||
|
||||
ts = nm_utils_clock_gettime_nsec(CLOCK_BOOTTIME);
|
||||
|
||||
msg = nm_vsprintf_buf_or_alloc(fmt, fmt, msg_stack, &msg_heap, NULL);
|
||||
|
||||
switch (level) {
|
||||
case LOGL_TRACE:
|
||||
level_str = "<trace>";
|
||||
break;
|
||||
case LOGL_DEBUG:
|
||||
level_str = "<debug>";
|
||||
break;
|
||||
case LOGL_INFO:
|
||||
level_str = "<info> ";
|
||||
break;
|
||||
case LOGL_WARN:
|
||||
level_str = "<warn> ";
|
||||
break;
|
||||
default:
|
||||
nm_assert(level == LOGL_ERR);
|
||||
level_str = "<error>";
|
||||
break;
|
||||
}
|
||||
|
||||
g_print("[%" G_GINT64_FORMAT ".%05" G_GINT64_FORMAT "] %s %s\n",
|
||||
ts / NM_UTILS_NSEC_PER_SEC,
|
||||
(ts / (NM_UTILS_NSEC_PER_SEC / 10000)) % 10000,
|
||||
level_str,
|
||||
msg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,4 +25,20 @@ extern const LogLevelDesc nm_log_level_desc[_LOGL_N];
|
|||
|
||||
gboolean _nm_log_parse_level(const char *level, NMLogLevel *out_level);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
extern volatile NMLogLevel _nm_logging_enabled_value;
|
||||
|
||||
static inline gboolean
|
||||
_nm_logging_enabled(NMLogLevel level)
|
||||
{
|
||||
return level >= _nm_logging_enabled_value;
|
||||
}
|
||||
|
||||
void _nm_logging_enabled_init(const char *level_str);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void _nm_log_simple_printf(NMLogLevel level, const char *fmt, ...) _nm_printf(2, 3);
|
||||
|
||||
#endif /* __NM_LOGGING_BASE_H__ */
|
||||
|
|
|
|||
|
|
@ -13,69 +13,6 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
volatile NMLogLevel _nm_logging_configured_level = LOGL_TRACE;
|
||||
|
||||
void
|
||||
_nm_logging_enabled_init(const char *level_str)
|
||||
{
|
||||
NMLogLevel level;
|
||||
|
||||
if (!_nm_log_parse_level(level_str, &level))
|
||||
level = LOGL_WARN;
|
||||
else if (level == _LOGL_KEEP)
|
||||
level = LOGL_WARN;
|
||||
|
||||
_nm_logging_configured_level = level;
|
||||
}
|
||||
|
||||
void
|
||||
_nm_log_impl_cs(NMLogLevel level, const char *fmt, ...)
|
||||
{
|
||||
gs_free char *msg = NULL;
|
||||
va_list ap;
|
||||
const char * level_str;
|
||||
gint64 ts;
|
||||
|
||||
va_start(ap, fmt);
|
||||
msg = g_strdup_vprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
switch (level) {
|
||||
case LOGL_TRACE:
|
||||
level_str = "<trace>";
|
||||
break;
|
||||
case LOGL_DEBUG:
|
||||
level_str = "<debug>";
|
||||
break;
|
||||
case LOGL_INFO:
|
||||
level_str = "<info> ";
|
||||
break;
|
||||
case LOGL_WARN:
|
||||
level_str = "<warn> ";
|
||||
break;
|
||||
default:
|
||||
nm_assert(level == LOGL_ERR);
|
||||
level_str = "<error>";
|
||||
break;
|
||||
}
|
||||
|
||||
ts = nm_utils_clock_gettime_nsec(CLOCK_BOOTTIME);
|
||||
|
||||
g_print("[%" G_GINT64_FORMAT ".%05" G_GINT64_FORMAT "] %s %s\n",
|
||||
ts / NM_UTILS_NSEC_PER_SEC,
|
||||
(ts / (NM_UTILS_NSEC_PER_SEC / 10000)) % 10000,
|
||||
level_str,
|
||||
msg);
|
||||
}
|
||||
|
||||
void
|
||||
_nm_utils_monotonic_timestamp_initialized(const struct timespec *tp,
|
||||
gint64 offset_sec,
|
||||
gboolean is_boottime)
|
||||
{}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
G_LOCK_DEFINE_STATIC(_wait_for_objects_lock);
|
||||
static GSList *_wait_for_objects_list;
|
||||
static GSList *_wait_for_objects_iterate_loops;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#ifndef __NM_CLOUD_SETUP_UTILS_H__
|
||||
#define __NM_CLOUD_SETUP_UTILS_H__
|
||||
|
||||
#include "libnm-glib-aux/nm-logging-fwd.h"
|
||||
#include "libnm-glib-aux/nm-logging-base.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -13,26 +13,14 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
extern volatile NMLogLevel _nm_logging_configured_level;
|
||||
|
||||
static inline gboolean
|
||||
nm_logging_enabled(NMLogLevel level)
|
||||
{
|
||||
return level >= _nm_logging_configured_level;
|
||||
}
|
||||
|
||||
void _nm_logging_enabled_init(const char *level_str);
|
||||
|
||||
void _nm_log_impl_cs(NMLogLevel level, const char *fmt, ...) _nm_printf(2, 3);
|
||||
|
||||
#define _nm_log(level, ...) _nm_log_impl_cs((level), __VA_ARGS__);
|
||||
#define _nm_log(level, ...) _nm_log_simple_printf((level), __VA_ARGS__);
|
||||
|
||||
#define _NMLOG(level, ...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
const NMLogLevel _level = (level); \
|
||||
\
|
||||
if (nm_logging_enabled(_level)) { \
|
||||
if (_nm_logging_enabled(_level)) { \
|
||||
_nm_log(_level, __VA_ARGS__); \
|
||||
} \
|
||||
} \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue