2004-02-24 00:41:20 +01:00
|
|
|
/* the Music Player Daemon (MPD)
|
2006-07-14 21:37:45 +02:00
|
|
|
* (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
|
2004-02-24 00:41:20 +01:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
#include "conf.h"
|
|
|
|
#include "myfprintf.h"
|
2004-06-12 04:06:16 +02:00
|
|
|
#include "utils.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2004-06-12 04:06:16 +02:00
|
|
|
#include <stdlib.h>
|
2004-02-24 00:41:20 +01:00
|
|
|
#include <string.h>
|
2004-06-12 04:06:16 +02:00
|
|
|
#include <stdarg.h>
|
2004-02-24 00:41:20 +01:00
|
|
|
|
|
|
|
int logLevel = LOG_LEVEL_LOW;
|
2004-06-12 04:06:16 +02:00
|
|
|
short warningFlushed = 0;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static char *warningBuffer = NULL;
|
|
|
|
|
|
|
|
void initLog(void)
|
|
|
|
{
|
|
|
|
ConfigParam *param = getConfigParam(CONF_LOG_LEVEL);
|
|
|
|
|
|
|
|
if (!param)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (0 == strcmp(param->value, "default")) {
|
|
|
|
if (logLevel < LOG_LEVEL_LOW)
|
|
|
|
logLevel = LOG_LEVEL_LOW;
|
|
|
|
} else if (0 == strcmp(param->value, "secure")) {
|
|
|
|
if (logLevel < LOG_LEVEL_SECURE)
|
|
|
|
logLevel = LOG_LEVEL_SECURE;
|
|
|
|
} else if (0 == strcmp(param->value, "verbose")) {
|
|
|
|
if (logLevel < LOG_LEVEL_DEBUG)
|
|
|
|
logLevel = LOG_LEVEL_DEBUG;
|
|
|
|
} else {
|
2004-10-28 07:14:55 +02:00
|
|
|
ERROR("unknown log level \"%s\" at line %i\n",
|
2006-07-20 18:02:40 +02:00
|
|
|
param->value, param->line);
|
2004-10-28 07:14:55 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2004-06-12 04:06:16 +02:00
|
|
|
|
|
|
|
#define BUFFER_LENGTH 4096
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void bufferWarning(char *format, ...)
|
|
|
|
{
|
2004-06-12 04:06:16 +02:00
|
|
|
va_list arglist;
|
2006-07-20 18:02:40 +02:00
|
|
|
char temp[BUFFER_LENGTH + 1];
|
2004-06-12 04:06:16 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
memset(temp, 0, BUFFER_LENGTH + 1);
|
2004-06-12 04:06:16 +02:00
|
|
|
|
|
|
|
va_start(arglist, format);
|
|
|
|
|
|
|
|
vsnprintf(temp, BUFFER_LENGTH, format, arglist);
|
|
|
|
|
|
|
|
warningBuffer = appendToString(warningBuffer, temp);
|
|
|
|
|
|
|
|
va_end(arglist);
|
|
|
|
}
|
2005-03-12 04:10:09 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void flushWarningLog(void)
|
|
|
|
{
|
|
|
|
char *s;
|
2004-06-12 04:06:16 +02:00
|
|
|
|
2005-03-12 04:10:09 +01:00
|
|
|
DEBUG("flushing warning messages\n");
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (warningBuffer == NULL)
|
|
|
|
return;
|
2004-06-12 04:06:16 +02:00
|
|
|
|
|
|
|
s = strtok(warningBuffer, "\n");
|
2006-07-20 18:02:40 +02:00
|
|
|
while (s != NULL) {
|
2006-07-31 01:32:39 +02:00
|
|
|
fdprintf(STDERR_FILENO, "%s\n", s);
|
2004-06-12 04:06:16 +02:00
|
|
|
|
|
|
|
s = strtok(NULL, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
free(warningBuffer);
|
|
|
|
warningBuffer = NULL;
|
|
|
|
|
|
|
|
warningFlushed = 1;
|
|
|
|
}
|