diff options
Diffstat (limited to 'libnm/nm-libnm-utils.c')
| -rw-r--r-- | libnm/nm-libnm-utils.c | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/libnm/nm-libnm-utils.c b/libnm/nm-libnm-utils.c index 9c27f64d..1fb6a47c 100644 --- a/libnm/nm-libnm-utils.c +++ b/libnm/nm-libnm-utils.c @@ -1,10 +1,10 @@ -/* SPDX-License-Identifier: LGPL-2.1+ */ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2007 - 2008 Novell, Inc. * Copyright (C) 2007 - 2018 Red Hat, Inc. */ -#include "nm-default.h" +#include "libnm/nm-default-libnm.h" #include "nm-libnm-utils.h" @@ -869,3 +869,42 @@ nm_utils_g_param_spec_is_default(const GParamSpec *pspec) * strictly asserts and only support argument types that we expect. */ g_return_val_if_reached(FALSE); } + +/*****************************************************************************/ + +/** + * nm_utils_print: + * @output_mode: if 1 it uses g_print(). If 2, it uses g_printerr(). + * If 0, it uses either g_print() or g_printerr(), depending + * on LIBNM_CLIENT_DEBUG (and the "stdout" flag). + * @msg: the message to print. The function does not append + * a trailing newline. + * + * The only purpose of this function is to give access to g_print() + * or g_printerr() from pygobject. libnm can do debug logging by + * setting LIBNM_CLIENT_DEBUG and uses thereby g_printerr() or + * g_print(). A plain "print()" function in python is not in sync + * with these functions (it implements additional buffering). By + * using nm_utils_print(), the same logging mechanisms can be used. + * + * Since: 1.30 + */ +void +nm_utils_print(int output_mode, const char *msg) +{ + gboolean use_stdout; + + g_return_if_fail(msg); + + if (output_mode == 0) { + nml_dbus_log_enabled_full(NML_DBUS_LOG_LEVEL_ANY, &use_stdout); + output_mode = use_stdout ? 1 : 2; + } + + if (output_mode == 1) + g_print("%s", msg); + else if (output_mode == 2) + g_printerr("%s", msg); + else + g_return_if_reached(); +} |