}
if (allowed) {
+ LOG_SetContext(LOGC_Command);
+
switch(rx_command) {
case REQ_NULL:
/* Do nothing */
tx_message.status = htons(STT_FAILED);
break;
}
+
+ LOG_UnsetContext(LOGC_Command);
} else {
tx_message.status = htons(STT_UNAUTH);
}
new_ids = ARR_GetElements(ntp_source_ids);
unresolved = 0;
+ LOG_SetContext(LOGC_SourceFile);
+
qsort(new_sources, new_size, sizeof (new_sources[0]), compare_sources);
for (i = j = 0; i < prev_size || j < new_size; ) {
}
}
+ LOG_UnsetContext(LOGC_SourceFile);
+
for (i = 0; i < prev_size; i++)
Free(prev_sources[i].params.name);
Free(prev_sources);
/* 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;
LOG_Initialise(void)
{
debug_prefix = Strdup("");
+ log_contexts = 0;
+
initialised = 1;
LOG_OpenFileLog(NULL);
}
/* ================================================== */
+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)
{
/* Get the minimum severity */
extern LOG_Severity LOG_GetMinSeverity(void);
+/* Flags for info messages that should be logged only in specific contexts */
+typedef enum {
+ LOGC_Command = 1,
+ LOGC_SourceFile = 2,
+} LOG_Context;
+
+/* Modify current contexts */
+extern void LOG_SetContext(LOG_Context context);
+extern void LOG_UnsetContext(LOG_Context context);
+
+/* Get severity depending on the current active contexts: INFO if they contain
+ at least one of the specified contexts, DEBUG otherwise */
+extern LOG_Severity LOG_GetContextSeverity(LOG_Context contexts);
+
/* Set a prefix for debug messages */
extern void LOG_SetDebugPrefix(const char *prefix);