Force all logs to go to the round robbin memory buffer

Initially only the log actually written out by libvirt were
saved on the memory buffer, this patch forces all informations
including info and debug to be saved in memory too. This is
useful to get full data in case of crash.
This commit is contained in:
Daniel Veillard 2011-03-02 20:26:02 +08:00
parent f8ac67909d
commit 8b9a1190c1

View File

@ -569,11 +569,12 @@ void virLogMessage(const char *category, int priority, const char *funcname,
long long linenr, int flags, const char *fmt, ...) { long long linenr, int flags, const char *fmt, ...) {
static bool logVersionStderr = true; static bool logVersionStderr = true;
char *str = NULL; char *str = NULL;
char *msg; char *msg = NULL;
struct timeval cur_time; struct timeval cur_time;
struct tm time_info; struct tm time_info;
int len, fprio, i, ret; int len, fprio, i, ret;
int saved_errno = errno; int saved_errno = errno;
int emit = 1;
if (!virLogInitialized) if (!virLogInitialized)
virLogStartup(); virLogStartup();
@ -587,9 +588,9 @@ void virLogMessage(const char *category, int priority, const char *funcname,
fprio = virLogFiltersCheck(category); fprio = virLogFiltersCheck(category);
if (fprio == 0) { if (fprio == 0) {
if (priority < virLogDefaultPriority) if (priority < virLogDefaultPriority)
goto cleanup; emit = 0;
} else if (priority < fprio) { } else if (priority < fprio) {
goto cleanup; emit = 0;
} }
/* /*
@ -609,8 +610,8 @@ void virLogMessage(const char *category, int priority, const char *funcname,
goto cleanup; goto cleanup;
/* /*
* Log based on defaults, first store in the history buffer * Log based on defaults, first store in the history buffer,
* then push the message on the outputs defined, if none * then if emit push the message on the outputs defined, if none
* use stderr. * use stderr.
* NOTE: the locking is a single point of contention for multiple * NOTE: the locking is a single point of contention for multiple
* threads, but avoid intermixing. Maybe set up locks per output * threads, but avoid intermixing. Maybe set up locks per output
@ -618,6 +619,9 @@ void virLogMessage(const char *category, int priority, const char *funcname,
*/ */
len = strlen(msg); len = strlen(msg);
virLogStr(msg, len); virLogStr(msg, len);
if (emit == 0)
goto cleanup;
virLogLock(); virLogLock();
for (i = 0; i < virLogNbOutputs;i++) { for (i = 0; i < virLogNbOutputs;i++) {
if (priority >= virLogOutputs[i].priority) { if (priority >= virLogOutputs[i].priority) {
@ -647,8 +651,8 @@ void virLogMessage(const char *category, int priority, const char *funcname,
} }
virLogUnlock(); virLogUnlock();
VIR_FREE(msg);
cleanup: cleanup:
VIR_FREE(msg);
errno = saved_errno; errno = saved_errno;
} }