mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 16:35:06 -05:00
logging: support context-specific severity
Allow messages to have severity set to INFO or DEBUG depending on the context in which they are made to allow logging important changes made from chronyc or sourcefile, but not spam the system log if those changes are normally expected (e.g. specified in the config).
This commit is contained in:
29
logging.c
29
logging.c
@@ -39,6 +39,9 @@
|
||||
/* This is used by DEBUG_LOG macro */
|
||||
LOG_Severity log_min_severity = LOGS_INFO;
|
||||
|
||||
/* Current logging contexts */
|
||||
static LOG_Context log_contexts;
|
||||
|
||||
/* ================================================== */
|
||||
/* Flag indicating we have initialised */
|
||||
static int initialised = 0;
|
||||
@@ -72,6 +75,8 @@ void
|
||||
LOG_Initialise(void)
|
||||
{
|
||||
debug_prefix = Strdup("");
|
||||
log_contexts = 0;
|
||||
|
||||
initialised = 1;
|
||||
LOG_OpenFileLog(NULL);
|
||||
}
|
||||
@@ -237,6 +242,30 @@ LOG_GetMinSeverity(void)
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
void
|
||||
LOG_SetContext(LOG_Context context)
|
||||
{
|
||||
log_contexts |= context;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
void
|
||||
LOG_UnsetContext(LOG_Context context)
|
||||
{
|
||||
log_contexts &= ~context;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
LOG_Severity
|
||||
LOG_GetContextSeverity(LOG_Context contexts)
|
||||
{
|
||||
return log_contexts & contexts ? LOGS_INFO : LOGS_DEBUG;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
void
|
||||
LOG_SetDebugPrefix(const char *prefix)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user