logging: make logging independent of platform
"nm-logging.h" is a basic core module that should have few other dependencies. Instead of letting nm-logging.c directly call a function from "nm-linux-platform.c", let platform register a handler as needed. This way, you can build a core library containing nm-logging but no nm-platform.
This commit is contained in:
@@ -39,7 +39,6 @@
|
|||||||
|
|
||||||
#include "nm-errors.h"
|
#include "nm-errors.h"
|
||||||
#include "NetworkManagerUtils.h"
|
#include "NetworkManagerUtils.h"
|
||||||
#include "nm-linux-platform.h"
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
LOG_FORMAT_FLAG_NONE = 0,
|
LOG_FORMAT_FLAG_NONE = 0,
|
||||||
@@ -71,6 +70,8 @@ typedef enum {
|
|||||||
LOG_FORMAT_FLAG_ALIGN_LOCATION,
|
LOG_FORMAT_FLAG_ALIGN_LOCATION,
|
||||||
} LogFormatFlags;
|
} LogFormatFlags;
|
||||||
|
|
||||||
|
void (*_nm_logging_clear_platform_logging_cache) (void);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nm_log_handler (const gchar *log_domain,
|
nm_log_handler (const gchar *log_domain,
|
||||||
GLogLevelFlags level,
|
GLogLevelFlags level,
|
||||||
@@ -332,11 +333,12 @@ nm_logging_setup (const char *level,
|
|||||||
global.logging[i] = new_logging[i];
|
global.logging[i] = new_logging[i];
|
||||||
|
|
||||||
if ( had_platform_debug
|
if ( had_platform_debug
|
||||||
|
&& _nm_logging_clear_platform_logging_cache
|
||||||
&& !nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) {
|
&& !nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) {
|
||||||
/* when debug logging is enabled, platform will cache all access to
|
/* when debug logging is enabled, platform will cache all access to
|
||||||
* sysctl. When the user disables debug-logging, we want to clear that
|
* sysctl. When the user disables debug-logging, we want to clear that
|
||||||
* cache right away. */
|
* cache right away. */
|
||||||
_nm_linux_platform_sysctl_clear_cache ();
|
_nm_logging_clear_platform_logging_cache ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unrecognized)
|
if (unrecognized)
|
||||||
|
@@ -243,6 +243,8 @@ void nm_logging_syslog_openlog (const char *logging_backend);
|
|||||||
#define _LOG2t_err(errsv, ...) G_STMT_START { if (FALSE) { _NMLOG2_err (errsv, LOGL_TRACE, __VA_ARGS__); } } G_STMT_END
|
#define _LOG2t_err(errsv, ...) G_STMT_START { if (FALSE) { _NMLOG2_err (errsv, LOGL_TRACE, __VA_ARGS__); } } G_STMT_END
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern void (*_nm_logging_clear_platform_logging_cache) (void);
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
#endif /* __NETWORKMANAGER_LOGGING_H__ */
|
#endif /* __NETWORKMANAGER_LOGGING_H__ */
|
||||||
|
@@ -2520,8 +2520,8 @@ sysctl_set (NMPlatform *platform, const char *path, const char *value)
|
|||||||
|
|
||||||
static GSList *sysctl_clear_cache_list;
|
static GSList *sysctl_clear_cache_list;
|
||||||
|
|
||||||
void
|
static void
|
||||||
_nm_linux_platform_sysctl_clear_cache (void)
|
_nm_logging_clear_platform_logging_cache_impl (void)
|
||||||
{
|
{
|
||||||
while (sysctl_clear_cache_list) {
|
while (sysctl_clear_cache_list) {
|
||||||
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (sysctl_clear_cache_list->data);
|
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (sysctl_clear_cache_list->data);
|
||||||
@@ -2541,6 +2541,7 @@ _log_dbg_sysctl_get_impl (NMPlatform *platform, const char *path, const char *co
|
|||||||
const char *prev_value = NULL;
|
const char *prev_value = NULL;
|
||||||
|
|
||||||
if (!priv->sysctl_get_prev_values) {
|
if (!priv->sysctl_get_prev_values) {
|
||||||
|
_nm_logging_clear_platform_logging_cache = _nm_logging_clear_platform_logging_cache_impl;
|
||||||
sysctl_clear_cache_list = g_slist_prepend (sysctl_clear_cache_list, platform);
|
sysctl_clear_cache_list = g_slist_prepend (sysctl_clear_cache_list, platform);
|
||||||
priv->sysctl_get_prev_values = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
priv->sysctl_get_prev_values = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||||
} else
|
} else
|
||||||
|
@@ -50,6 +50,4 @@ GType nm_linux_platform_get_type (void);
|
|||||||
|
|
||||||
void nm_linux_platform_setup (void);
|
void nm_linux_platform_setup (void);
|
||||||
|
|
||||||
void _nm_linux_platform_sysctl_clear_cache (void);
|
|
||||||
|
|
||||||
#endif /* __NETWORKMANAGER_LINUX_PLATFORM_H__ */
|
#endif /* __NETWORKMANAGER_LINUX_PLATFORM_H__ */
|
||||||
|
Reference in New Issue
Block a user