Add WARNING log method. it's the same as ERROR, except that when mpd starts,
warnings are buffered until the error log is opened, and then flushed to the error log. git-svn-id: https://svn.musicpd.org/mpd/trunk@1442 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
41
src/log.c
41
src/log.c
@@ -20,10 +20,16 @@
|
||||
|
||||
#include "conf.h"
|
||||
#include "myfprintf.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int logLevel = LOG_LEVEL_LOW;
|
||||
short warningFlushed = 0;
|
||||
|
||||
static char * warningBuffer = NULL;
|
||||
|
||||
void initLog() {
|
||||
if(strcmp(getConf()[CONF_LOG_LEVEL],"default")==0) {
|
||||
@@ -37,4 +43,37 @@ void initLog() {
|
||||
}
|
||||
else ERROR("unknown log level \"%s\"\n",getConf()[CONF_LOG_LEVEL]);
|
||||
}
|
||||
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
|
||||
|
||||
#define BUFFER_LENGTH 4096
|
||||
|
||||
void bufferWarning(char * format, ... ) {
|
||||
va_list arglist;
|
||||
char temp[BUFFER_LENGTH+1];
|
||||
|
||||
memset(temp, 0, BUFFER_LENGTH+1);
|
||||
|
||||
va_start(arglist, format);
|
||||
|
||||
vsnprintf(temp, BUFFER_LENGTH, format, arglist);
|
||||
|
||||
warningBuffer = appendToString(warningBuffer, temp);
|
||||
|
||||
va_end(arglist);
|
||||
}
|
||||
void flushWarningLog() {
|
||||
char * s;
|
||||
|
||||
if(warningBuffer == NULL) return;
|
||||
|
||||
s = strtok(warningBuffer, "\n");
|
||||
while ( s != NULL ) {
|
||||
myfprintf(stderr, "%s\n", s);
|
||||
|
||||
s = strtok(NULL, "\n");
|
||||
}
|
||||
|
||||
free(warningBuffer);
|
||||
warningBuffer = NULL;
|
||||
|
||||
warningFlushed = 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user