log: new helper to allow printing or hiding personal info
This commit is contained in:
13
src/mm-log.c
13
src/mm-log.c
@@ -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 GTimeVal rel_start = { 0, 0 };
|
||||||
static int logfd = -1;
|
static int logfd = -1;
|
||||||
static gboolean append_log_level_text = TRUE;
|
static gboolean append_log_level_text = TRUE;
|
||||||
|
static gboolean personal_info = FALSE;
|
||||||
|
|
||||||
static void (*log_backend) (const char *loc,
|
static void (*log_backend) (const char *loc,
|
||||||
const char *func,
|
const char *func,
|
||||||
@@ -331,6 +332,8 @@ mm_log_setup (const gchar *level,
|
|||||||
if (level && strlen (level) && !mm_log_set_level (level, error))
|
if (level && strlen (level) && !mm_log_set_level (level, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
personal_info = show_personal_info;
|
||||||
|
|
||||||
if (show_timestamps)
|
if (show_timestamps)
|
||||||
ts_flags = TS_FLAG_WALL;
|
ts_flags = TS_FLAG_WALL;
|
||||||
else if (rel_timestamps)
|
else if (rel_timestamps)
|
||||||
@@ -400,3 +403,13 @@ mm_log_shutdown (void)
|
|||||||
else
|
else
|
||||||
close (logfd);
|
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;
|
||||||
|
}
|
||||||
|
@@ -68,4 +68,9 @@ gboolean mm_log_setup (const gchar *level,
|
|||||||
GError **error);
|
GError **error);
|
||||||
void mm_log_shutdown (void);
|
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 */
|
#endif /* MM_LOG_H */
|
||||||
|
Reference in New Issue
Block a user