logging: extend functionality
Add a function to get the current minimum severity and a function to set a global prefix for debug messages in order to identify messages from helpers.
This commit is contained in:
parent
2bb0769516
commit
51d77d6cfc
2 changed files with 33 additions and 1 deletions
28
logging.c
28
logging.c
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include "conf.h"
|
||||
#include "logging.h"
|
||||
#include "memory.h"
|
||||
#include "util.h"
|
||||
|
||||
/* This is used by DEBUG_LOG macro */
|
||||
|
@ -61,12 +62,16 @@ static int n_filelogs = 0;
|
|||
|
||||
static struct LogFile logfiles[MAX_FILELOGS];
|
||||
|
||||
/* Global prefix for debug messages */
|
||||
static char *debug_prefix;
|
||||
|
||||
/* ================================================== */
|
||||
/* Init function */
|
||||
|
||||
void
|
||||
LOG_Initialise(void)
|
||||
{
|
||||
debug_prefix = Strdup("");
|
||||
initialised = 1;
|
||||
LOG_OpenFileLog(NULL);
|
||||
}
|
||||
|
@ -85,6 +90,8 @@ LOG_Finalise(void)
|
|||
|
||||
LOG_CycleLogFiles();
|
||||
|
||||
Free(debug_prefix);
|
||||
|
||||
initialised = 0;
|
||||
}
|
||||
|
||||
|
@ -132,6 +139,8 @@ void LOG_Message(LOG_Severity severity,
|
|||
time_t t;
|
||||
struct tm *tm;
|
||||
|
||||
assert(initialised);
|
||||
|
||||
if (!system_log && file_log && severity >= log_min_severity) {
|
||||
/* Don't clutter up syslog with timestamps and internal debugging info */
|
||||
time(&t);
|
||||
|
@ -142,7 +151,7 @@ void LOG_Message(LOG_Severity severity,
|
|||
}
|
||||
#if DEBUG > 0
|
||||
if (log_min_severity <= LOGS_DEBUG)
|
||||
fprintf(file_log, "%s:%d:(%s) ", filename, line_number, function_name);
|
||||
fprintf(file_log, "%s%s:%d:(%s) ", debug_prefix, filename, line_number, function_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -220,6 +229,23 @@ void LOG_SetMinSeverity(LOG_Severity severity)
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
LOG_Severity
|
||||
LOG_GetMinSeverity(void)
|
||||
{
|
||||
return log_min_severity;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
void
|
||||
LOG_SetDebugPrefix(const char *prefix)
|
||||
{
|
||||
Free(debug_prefix);
|
||||
debug_prefix = Strdup(prefix);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
void
|
||||
LOG_SetParentFd(int fd)
|
||||
{
|
||||
|
|
|
@ -97,6 +97,12 @@ extern void LOG_Message(LOG_Severity severity, const char *format, ...);
|
|||
prefixed with the filename, line number, and function name. */
|
||||
extern void LOG_SetMinSeverity(LOG_Severity severity);
|
||||
|
||||
/* Get the minimum severity */
|
||||
extern LOG_Severity LOG_GetMinSeverity(void);
|
||||
|
||||
/* Set a prefix for debug messages */
|
||||
extern void LOG_SetDebugPrefix(const char *prefix);
|
||||
|
||||
/* Log messages to a file instead of stderr, or stderr again if NULL */
|
||||
extern void LOG_OpenFileLog(const char *log_file);
|
||||
|
||||
|
|
Loading…
Reference in a new issue