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:
Warren Dukes 2004-06-12 02:06:16 +00:00
parent 43255a7f63
commit 43b355734c
11 changed files with 106 additions and 38 deletions

2
TODO
View File

@ -1,7 +1,5 @@
*) put some sort of error reporting for streaming/inputStream! *) put some sort of error reporting for streaming/inputStream!
*) Fix charset errors so they don't goto stderr/out
Post-1.0 Post-1.0
-------- --------
1) crosslink "list" stuff, for example, artists are crosslinked to alubms and 1) crosslink "list" stuff, for example, artists are crosslinked to alubms and

View File

@ -256,7 +256,7 @@ int playAudio(char * playChunk, int size) {
int send; int send;
if(audio_device==NULL) { if(audio_device==NULL) {
ERROR("trying to play w/ the audio device being open!\n"); ERROR("trying to play w/o the audio device being open!\n");
return -1; return -1;
} }
@ -302,4 +302,3 @@ void audioError() {
} }
#endif #endif
} }
/* vim:set shiftwidth=4 tabstop=8 expandtab: */

View File

@ -931,7 +931,7 @@ int readDirectoryDB() {
char * tempCharset; char * tempCharset;
if(foundFsCharset) { if(foundFsCharset) {
ERROR("already found " WARNING("already found "
"fs charset in db\n"); "fs charset in db\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -944,11 +944,11 @@ int readDirectoryDB() {
getConf()[CONF_FS_CHARSET]) && getConf()[CONF_FS_CHARSET]) &&
strcmp(fsCharset,tempCharset)) strcmp(fsCharset,tempCharset))
{ {
ERROR("Using \"%s\" for the " WARNING("Using \"%s\" for the "
"filesystem charset " "filesystem charset "
"instead of \"%s\"\n", "instead of \"%s\"\n",
fsCharset,tempCharset); fsCharset,tempCharset);
ERROR("maybe you need to " WARNING("maybe you need to "
"recreate the db?\n"); "recreate the db?\n");
setFsCharset(fsCharset); setFsCharset(fsCharset);
} }
@ -1275,4 +1275,3 @@ Song * getSongFromDB(char * file) {
time_t getDbModTime() { time_t getDbModTime() {
return directory_dbModTime; return directory_dbModTime;
} }
/* vim:set shiftwidth=4 tabstop=8 expandtab: */

View File

@ -20,10 +20,16 @@
#include "conf.h" #include "conf.h"
#include "myfprintf.h" #include "myfprintf.h"
#include "utils.h"
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
int logLevel = LOG_LEVEL_LOW; int logLevel = LOG_LEVEL_LOW;
short warningFlushed = 0;
static char * warningBuffer = NULL;
void initLog() { void initLog() {
if(strcmp(getConf()[CONF_LOG_LEVEL],"default")==0) { 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]); 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;
}

View File

@ -28,6 +28,7 @@
#define LOG_LEVEL_DEBUG 2 #define LOG_LEVEL_DEBUG 2
extern int logLevel; extern int logLevel;
extern short warningFlushed;
#define ERROR(...) myfprintf(stderr, __VA_ARGS__) #define ERROR(...) myfprintf(stderr, __VA_ARGS__)
@ -40,7 +41,15 @@ extern int logLevel;
#define DEBUG(...) if(logLevel>=LOG_LEVEL_DEBUG) \ #define DEBUG(...) if(logLevel>=LOG_LEVEL_DEBUG) \
myfprintf(stdout, __VA_ARGS__) myfprintf(stdout, __VA_ARGS__)
#define WARNING(...) { \
if(warningFlushed) myfprintf(stderr, __VA_ARGS__); \
else bufferWarning(__VA_ARGS__); \
}
void initLog(); void initLog();
void bufferWarning(char * format, ... );
void flushWarningLog();
#endif #endif
/* vim:set shiftwidth=4 tabstop=8 expandtab: */

View File

@ -289,7 +289,10 @@ void changeToUser(Options * options) {
} }
void openLogFiles(Options * options, FILE ** out, FILE ** err) { void openLogFiles(Options * options, FILE ** out, FILE ** err) {
if(options->stdOutput) return; if(options->stdOutput) {
flushWarningLog();
return;
}
if(NULL==(*out=fopen(options->logFile,"a"))) { if(NULL==(*out=fopen(options->logFile,"a"))) {
ERROR("problem opening file \"%s\" for writing\n", ERROR("problem opening file \"%s\" for writing\n",
@ -316,6 +319,7 @@ void openDB(Options * options, char * argv0) {
argv0); argv0);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
flushWarningLog();
initMp3Directory(); initMp3Directory();
if(writeDirectoryDB()<0) { if(writeDirectoryDB()<0) {
ERROR("problem opening db for reading or writing\n"); ERROR("problem opening db for reading or writing\n");
@ -324,6 +328,7 @@ void openDB(Options * options, char * argv0) {
if(options->createDB) exit(EXIT_SUCCESS); if(options->createDB) exit(EXIT_SUCCESS);
} }
if(options->updateDB) { if(options->updateDB) {
flushWarningLog();
updateMp3Directory(); updateMp3Directory();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
@ -379,6 +384,7 @@ void setupLogOutput(Options * options, FILE * out, FILE * err) {
myfprintfStdLogMode(out, err, options->logFile, myfprintfStdLogMode(out, err, options->logFile,
options->errorFile); options->errorFile);
flushWarningLog();
} }
/* lets redirect stdin to dev null as a work around for libao bug */ /* lets redirect stdin to dev null as a work around for libao bug */

View File

@ -31,4 +31,3 @@ void myfprintf(FILE * fp, char * format, ... );
int myfprintfCloseAndOpenLogFile(); int myfprintfCloseAndOpenLogFile();
#endif #endif
/* vim:set shiftwidth=4 tabstop=8 expandtab: */

View File

@ -86,13 +86,13 @@ void setFsCharset(char * charset) {
DEBUG("setFsCharset: fs charset is: %s\n",fsCharset); DEBUG("setFsCharset: fs charset is: %s\n",fsCharset);
if(setCharSetConversion("UTF-8",fsCharset)!=0) { if(setCharSetConversion("UTF-8",fsCharset)!=0) {
ERROR("fs charset conversion problem: " WARNING("fs charset conversion problem: "
"not able to convert from \"%s\" to \"%s\"\n", "not able to convert from \"%s\" to \"%s\"\n",
fsCharset,"UTF-8"); fsCharset,"UTF-8");
error = 1; error = 1;
} }
if(setCharSetConversion(fsCharset,"UTF-8")!=0) { if(setCharSetConversion(fsCharset,"UTF-8")!=0) {
ERROR("fs charset conversion problem: " WARNING("fs charset conversion problem: "
"not able to convert from \"%s\" to \"%s\"\n", "not able to convert from \"%s\" to \"%s\"\n",
"UTF-8",fsCharset); "UTF-8",fsCharset);
error = 1; error = 1;
@ -100,7 +100,7 @@ void setFsCharset(char * charset) {
if(error) { if(error) {
free(fsCharset); free(fsCharset);
ERROR("setting fs charset to ISO-8859-1!\n"); WARNING("setting fs charset to ISO-8859-1!\n");
fsCharset = strdup("ISO-8859-1"); fsCharset = strdup("ISO-8859-1");
} }
} }
@ -145,28 +145,28 @@ void initPaths(char * playlistDirArg, char * musicDirArg) {
originalLocale = strdup(originalLocale); originalLocale = strdup(originalLocale);
if(!(currentLocale = setlocale(LC_CTYPE,""))) { if(!(currentLocale = setlocale(LC_CTYPE,""))) {
ERROR("problems setting current locale with " WARNING("problems setting current locale with "
"setlocale()\n"); "setlocale()\n");
} }
else { else {
if(strcmp(currentLocale,"C")==0 || if(strcmp(currentLocale,"C")==0 ||
strcmp(currentLocale,"POSIX")==0) strcmp(currentLocale,"POSIX")==0)
{ {
ERROR("current locale is \"%s\"\n", WARNING("current locale is \"%s\"\n",
currentLocale); currentLocale);
} }
else if((temp = nl_langinfo(CODESET))) { else if((temp = nl_langinfo(CODESET))) {
charset = strdup(temp); charset = strdup(temp);
} }
else ERROR("problems getting charset for locale\n"); else WARNING("problems getting charset for locale\n");
if(!setlocale(LC_CTYPE,originalLocale)) { if(!setlocale(LC_CTYPE,originalLocale)) {
ERROR("problems resetting locale with setlocale()\n"); WARNING("problems resetting locale with setlocale()\n");
} }
} }
free(originalLocale); free(originalLocale);
} }
else ERROR("problems getting locale with setlocale()\n"); else WARNING("problems getting locale with setlocale()\n");
#endif #endif
#endif #endif
@ -175,7 +175,7 @@ void initPaths(char * playlistDirArg, char * musicDirArg) {
free(charset); free(charset);
} }
else { else {
ERROR("setting filesystem charset to ISO-8859-1\n"); WARNING("setting filesystem charset to ISO-8859-1\n");
setFsCharset("ISO-8859-1"); setFsCharset("ISO-8859-1");
} }
} }

View File

@ -70,4 +70,22 @@ int ipv6Supported() {
return 0; return 0;
} }
/* vim:set shiftwidth=4 tabstop=8 expandtab: */ char * appendToString(char * dest, const char * src) {
int destlen;
int srclen = strlen(src);
if(dest == NULL) {
dest = malloc(srclen+1);
memset(dest, 0, srclen+1);
destlen = 0;
}
else {
destlen = strlen(dest);
dest = realloc(dest, destlen+srclen+1);
}
memcpy(dest+destlen, src, srclen);
dest[destlen+srclen] = '\0';
return dest;
}

View File

@ -33,5 +33,6 @@ void my_usleep(long usec);
int ipv6Supported(); int ipv6Supported();
char * appendToString(char * dest, const char * src);
#endif #endif
/* vim:set shiftwidth=4 tabstop=8 expandtab: */

View File

@ -68,7 +68,7 @@ int prepOssMixer(char * device) {
int devmask = 0; int devmask = 0;
if((volume_ossFd = open(device,O_RDONLY))<0) { if((volume_ossFd = open(device,O_RDONLY))<0) {
ERROR("unable to open oss mixer \"%s\"\n",device); WARNING("unable to open oss mixer \"%s\"\n",device);
return -1; return -1;
} }
@ -78,7 +78,7 @@ int prepOssMixer(char * device) {
int i,j; int i,j;
if(ioctl(volume_ossFd,SOUND_MIXER_READ_DEVMASK,&devmask)<0) { if(ioctl(volume_ossFd,SOUND_MIXER_READ_DEVMASK,&devmask)<0) {
ERROR("errors getting read_devmask for oss mixer\n"); WARNING("errors getting read_devmask for oss mixer\n");
close(volume_ossFd); close(volume_ossFd);
return -1; return -1;
} }
@ -96,13 +96,13 @@ int prepOssMixer(char * device) {
} }
if(i>=SOUND_MIXER_NRDEVICES) { if(i>=SOUND_MIXER_NRDEVICES) {
ERROR("mixer control \"%s\" not found\n", WARNING("mixer control \"%s\" not found\n",
getConf()[CONF_MIXER_CONTROL]); getConf()[CONF_MIXER_CONTROL]);
close(volume_ossFd); close(volume_ossFd);
return -1; return -1;
} }
else if(!( ( 1 << i ) & devmask )) { else if(!( ( 1 << i ) & devmask )) {
ERROR("mixer control \"%s\" not usable\n", WARNING("mixer control \"%s\" not usable\n",
getConf()[CONF_MIXER_CONTROL]); getConf()[CONF_MIXER_CONTROL]);
close(volume_ossFd); close(volume_ossFd);
return -1; return -1;
@ -122,7 +122,7 @@ int getOssVolumeLevel() {
int left, right, level; int left, right, level;
if(ioctl(volume_ossFd,MIXER_READ(volume_ossControl),&level) < 0) { if(ioctl(volume_ossFd,MIXER_READ(volume_ossControl),&level) < 0) {
ERROR("unable to read volume\n"); WARNING("unable to read volume\n");
return -1; return -1;
} }
@ -130,7 +130,7 @@ int getOssVolumeLevel() {
right = (level & 0xff00) >> 8; right = (level & 0xff00) >> 8;
if(left!=right) { if(left!=right) {
ERROR("volume for left and right is not the same, \"%i\" and " WARNING("volume for left and right is not the same, \"%i\" and "
"\"%i\"\n",left,right); "\"%i\"\n",left,right);
} }
@ -174,27 +174,27 @@ int prepAlsaMixer(char * card) {
char * controlName = VOLUME_MIXER_ALSA_CONTROL_DEFAULT; char * controlName = VOLUME_MIXER_ALSA_CONTROL_DEFAULT;
if((err = snd_mixer_open(&volume_alsaMixerHandle,0))<0) { if((err = snd_mixer_open(&volume_alsaMixerHandle,0))<0) {
ERROR("problems opening alsa mixer: %s\n",snd_strerror(err)); WARNING("problems opening alsa mixer: %s\n",snd_strerror(err));
return -1; return -1;
} }
if((err = snd_mixer_attach(volume_alsaMixerHandle,card))<0) { if((err = snd_mixer_attach(volume_alsaMixerHandle,card))<0) {
snd_mixer_close(volume_alsaMixerHandle); snd_mixer_close(volume_alsaMixerHandle);
ERROR("problems problems attaching alsa mixer: %s\n", WARNING("problems problems attaching alsa mixer: %s\n",
snd_strerror(err)); snd_strerror(err));
return -1; return -1;
} }
if((err = snd_mixer_selem_register(volume_alsaMixerHandle,NULL,NULL))<0) { if((err = snd_mixer_selem_register(volume_alsaMixerHandle,NULL,NULL))<0) {
snd_mixer_close(volume_alsaMixerHandle); snd_mixer_close(volume_alsaMixerHandle);
ERROR("problems snd_mixer_selem_register'ing: %s\n", WARNING("problems snd_mixer_selem_register'ing: %s\n",
snd_strerror(err)); snd_strerror(err));
return -1; return -1;
} }
if((err = snd_mixer_load(volume_alsaMixerHandle))<0) { if((err = snd_mixer_load(volume_alsaMixerHandle))<0) {
snd_mixer_close(volume_alsaMixerHandle); snd_mixer_close(volume_alsaMixerHandle);
ERROR("problems snd_mixer_selem_register'ing: %s\n", WARNING("problems snd_mixer_selem_register'ing: %s\n",
snd_strerror(err)); snd_strerror(err));
return -1; return -1;
} }
@ -223,7 +223,7 @@ int prepAlsaMixer(char * card) {
return 0; return 0;
} }
ERROR("can't find alsa mixer_control \"%s\"\n",controlName); WARNING("can't find alsa mixer_control \"%s\"\n",controlName);
snd_mixer_close(volume_alsaMixerHandle); snd_mixer_close(volume_alsaMixerHandle);
return -1; return -1;
@ -244,7 +244,7 @@ int getAlsaVolumeLevel() {
if((err = snd_mixer_selem_get_playback_volume(volume_alsaElem, if((err = snd_mixer_selem_get_playback_volume(volume_alsaElem,
SND_MIXER_SCHN_FRONT_LEFT,&level))<0) { SND_MIXER_SCHN_FRONT_LEFT,&level))<0) {
ERROR("problems getting alsa volume: %s\n",snd_strerror(err)); WARNING("problems getting alsa volume: %s\n",snd_strerror(err));
return -1; return -1;
} }
@ -272,7 +272,7 @@ int changeAlsaVolumeLevel(FILE * fp, int change, int rel) {
if((err = snd_mixer_selem_get_playback_volume(volume_alsaElem, if((err = snd_mixer_selem_get_playback_volume(volume_alsaElem,
SND_MIXER_SCHN_FRONT_LEFT,&level))<0) { SND_MIXER_SCHN_FRONT_LEFT,&level))<0) {
commandError(fp, ACK_ERROR_SYSTEM, "problems getting volume"); commandError(fp, ACK_ERROR_SYSTEM, "problems getting volume");
ERROR("problems getting alsa volume: %s\n",snd_strerror(err)); WARNING("problems getting alsa volume: %s\n",snd_strerror(err));
return -1; return -1;
} }
@ -298,7 +298,7 @@ int changeAlsaVolumeLevel(FILE * fp, int change, int rel) {
if((err = snd_mixer_selem_set_playback_volume_all( if((err = snd_mixer_selem_set_playback_volume_all(
volume_alsaElem,level))<0) { volume_alsaElem,level))<0) {
commandError(fp, ACK_ERROR_SYSTEM, "problems setting volume"); commandError(fp, ACK_ERROR_SYSTEM, "problems setting volume");
ERROR("problems setting alsa volume: %s\n",snd_strerror(err)); WARNING("problems setting alsa volume: %s\n",snd_strerror(err));
return -1; return -1;
} }
@ -365,7 +365,7 @@ void initVolume() {
void openVolumeDevice() { void openVolumeDevice() {
if(prepMixer(volume_mixerDevice)<0) { if(prepMixer(volume_mixerDevice)<0) {
ERROR("using software volume\n"); WARNING("using software volume\n");
volume_mixerType = VOLUME_MIXER_TYPE_SOFTWARE; volume_mixerType = VOLUME_MIXER_TYPE_SOFTWARE;
} }
} }