log: new helper to allow printing or hiding personal info

This commit is contained in:
Aleksander Morgado
2022-08-12 13:09:50 +00:00
parent ddfdbf66f6
commit f19aa4d99a
2 changed files with 18 additions and 0 deletions

View File

@@ -56,6 +56,7 @@ static guint32 log_level = MM_LOG_LEVEL_MSG | MM_LOG_LEVEL_WARN | MM_LOG_LEVEL_
static GTimeVal rel_start = { 0, 0 };
static int logfd = -1;
static gboolean append_log_level_text = TRUE;
static gboolean personal_info = FALSE;
static void (*log_backend) (const char *loc,
const char *func,
@@ -331,6 +332,8 @@ mm_log_setup (const gchar *level,
if (level && strlen (level) && !mm_log_set_level (level, error))
return FALSE;
personal_info = show_personal_info;
if (show_timestamps)
ts_flags = TS_FLAG_WALL;
else if (rel_timestamps)
@@ -400,3 +403,13 @@ mm_log_shutdown (void)
else
close (logfd);
}
/******************************************************************************/
const gchar *
mm_log_str_personal_info (const gchar *str)
{
static const gchar *hidden_personal_info = "###";
return personal_info ? str : hidden_personal_info;
}

View File

@@ -68,4 +68,9 @@ gboolean mm_log_setup (const gchar *level,
GError **error);
void mm_log_shutdown (void);
/* Helper used when printing a string that may be personal
* info. Depending on the settings, we may print it as-is,
* or otherwise provide a fallback string. */
const gchar *mm_log_str_personal_info (const gchar *str);
#endif /* MM_LOG_H */