Use new logger facility

This commit is contained in:
Julien BLACHE 2009-05-08 17:46:32 +02:00
parent 3a2a218a0f
commit 11fd038d16
19 changed files with 82 additions and 41 deletions

View File

@ -30,7 +30,7 @@
#include <confuse.h>
#include "err.h"
#include "logger.h"
#include "conffile.h"

View File

@ -39,7 +39,7 @@
#endif
#include "db-generic.h"
#include "err.h"
#include "logger.h"
#include "db-sql.h"

View File

@ -47,7 +47,7 @@
# include <unistd.h>
#endif
#include "err.h"
#include "logger.h"
#include "db-generic.h"
#include "db-sql.h"
#include "db-sql-sqlite3.h"

View File

@ -38,11 +38,14 @@
#endif
#include <inttypes.h>
#include "err.h"
#include "logger.h"
#include "db-generic.h"
#include "db-sql.h"
#include "smart-parser.h"
#define TRUE ((1 == 1))
#define FALSE (!TRUE)
#ifdef HAVE_SQLITE3
#include "db-sql-sqlite3.h"
#endif

View File

@ -42,7 +42,7 @@
#include <event.h>
#include <avl.h>
#include "err.h"
#include "logger.h"
#include "db-generic.h"
#include "filescanner.h"
#include "conffile.h"

View File

@ -36,7 +36,7 @@
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include "err.h"
#include "logger.h"
#include "filescanner.h"

View File

@ -33,7 +33,7 @@
#include <sys/stat.h>
#include <errno.h>
#include "err.h"
#include "logger.h"
#include "ff-dbstruct.h"
#include "db-generic.h"
#include "filescanner.h"

View File

@ -30,7 +30,7 @@
#include <limits.h>
#include <errno.h>
#include "err.h"
#include "logger.h"
#include "ff-dbstruct.h"
#include "filescanner.h"

View File

@ -34,7 +34,7 @@
#include <event.h>
#include "evhttp/evhttp.h"
#include "err.h"
#include "logger.h"
#include "ff-dbstruct.h"
#include "db-generic.h"
#include "conffile.h"

View File

@ -38,7 +38,7 @@
#include "evhttp/evhttp.h"
#include <avl.h>
#include "err.h"
#include "logger.h"
#include "ff-dbstruct.h"
#include "db-generic.h"
#include "conffile.h"

View File

@ -37,7 +37,7 @@
#include <mxml.h>
#include "err.h"
#include "logger.h"
#include "ff-dbstruct.h"
#include "db-generic.h"
#include "conffile.h"

View File

@ -81,7 +81,7 @@
#include <grp.h>
#include "conffile.h"
#include "err.h"
#include "logger.h"
#include "misc.h"
#include "filescanner.h"
#include "httpd.h"
@ -128,8 +128,8 @@ static void usage(char *program);
void usage(char *program) {
printf("Usage: %s [options]\n\n",program);
printf("Options:\n");
printf(" -d <number> Debug level (0-9)\n");
printf(" -D <mod,mod..> Debug modules\n");
printf(" -d <number> Log level (0-5)\n");
printf(" -D <dom,dom..> Log domains\n");
printf(" -c <file> Use configfile specified\n");
printf(" -P <file> Write the PID to specified file\n");
printf(" -f Run in foreground\n");
@ -137,9 +137,8 @@ void usage(char *program) {
printf(" -b <id> ffid to be broadcast\n");
printf(" -v Display version information\n");
printf("\n\n");
printf("Valid debug modules:\n");
printf(" config,webserver,database,scan,query,index,browse\n");
printf(" playlist,art,daap,main,rend,misc\n");
printf("Available log domains:\n");
logger_domains();
printf("\n\n");
}
@ -214,6 +213,8 @@ daemonize(int background, char *runas, char *pidfile)
return -1;
}
logger_detach();
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
@ -299,7 +300,7 @@ signal_cb(int fd, short event, void *arg)
DPRINTF(E_LOG, L_MAIN, "Got SIGHUP\n");
if (!main_exit)
err_reopen();
logger_reinit();
break;
}
}
@ -349,9 +350,9 @@ int main(int argc, char *argv[]) {
int err;
int debuglevel=0;
err_setlevel(2);
int loglevel = -1;
char *logdomains = NULL;
char *logfile = NULL;
background = 1;
@ -362,20 +363,15 @@ int main(int argc, char *argv[]) {
break;
case 'd':
debuglevel = atoi(optarg);
err_setlevel(debuglevel);
loglevel = atoi(optarg);
break;
case 'D':
if(err_setdebugmask(optarg)) {
usage(argv[0]);
exit(EXIT_FAILURE);
}
logdomains = optarg;
break;
case 'f':
background = 0;
err_setdest(err_getdest() | LOGDEST_STDERR);
break;
case 'c':
@ -417,19 +413,41 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}
ret = conffile_load(configfile);
ret = logger_init(NULL, NULL, (loglevel < 0) ? E_LOG : loglevel);
if (ret != 0)
{
fprintf(stderr, "Config file errors; please fix your config\n");
fprintf(stderr, "Could not initialize log facility\n");
exit(EXIT_FAILURE);
}
if(debuglevel) /* was specified, should override the config file */
err_setlevel(debuglevel);
ret = conffile_load(configfile);
if (ret != 0)
{
DPRINTF(E_FATAL, L_MAIN, "Config file errors; please fix your config\n");
DPRINTF(E_LOG,L_MAIN,"Firefly Version %s: Starting with debuglevel %d\n",
VERSION,err_getlevel());
logger_deinit();
exit(EXIT_FAILURE);
}
logger_deinit();
/* Reinit log facility with configfile values */
if (loglevel < 0)
loglevel = cfg_getint(cfg_getsec(cfg, "general"), "loglevel");
logfile = cfg_getstr(cfg_getsec(cfg, "general"), "logfile");
ret = logger_init(logfile, logdomains, loglevel);
if (ret != 0)
{
fprintf(stderr, "Could not reinitialize log facility with config file settings\n");
conffile_unload();
exit(EXIT_FAILURE);
}
DPRINTF(E_LOG, L_MAIN, "Firefly Version %s taking off\n", VERSION);
/* initialize ffmpeg */
av_register_all();
@ -445,6 +463,8 @@ int main(int argc, char *argv[]) {
if (ret != 0)
{
DPRINTF(E_LOG, L_MAIN, "Error setting signal set\n");
logger_deinit();
exit(EXIT_FAILURE);
}
@ -456,6 +476,7 @@ int main(int argc, char *argv[]) {
{
DPRINTF(E_LOG, L_MAIN, "Could not initialize server\n");
logger_deinit();
exit(EXIT_FAILURE);
}
@ -468,6 +489,7 @@ int main(int argc, char *argv[]) {
{
DPRINTF(E_FATAL, L_MAIN, "mDNS init failed\n");
logger_deinit();
exit(EXIT_FAILURE);
}
@ -478,6 +500,7 @@ int main(int argc, char *argv[]) {
DPRINTF(E_LOG,L_MAIN,"Error opening db: %s\n",perr);
mdns_deinit();
logger_deinit();
exit(EXIT_FAILURE);
}
@ -495,6 +518,7 @@ int main(int argc, char *argv[]) {
mdns_deinit();
db_deinit();
logger_deinit();
exit(EXIT_FAILURE);
}
@ -506,6 +530,7 @@ int main(int argc, char *argv[]) {
mdns_deinit();
db_deinit();
logger_deinit();
exit(EXIT_FAILURE);
}
@ -525,6 +550,7 @@ int main(int argc, char *argv[]) {
filescanner_deinit();
mdns_deinit();
db_deinit();
logger_deinit();
exit(EXIT_FAILURE);
}
@ -575,6 +601,7 @@ int main(int argc, char *argv[]) {
filescanner_deinit();
mdns_deinit();
db_deinit();
logger_deinit();
exit(EXIT_FAILURE);
}
@ -610,6 +637,8 @@ int main(int argc, char *argv[]) {
DPRINTF(E_LOG,L_MAIN,"Done!\n");
logger_deinit();
return EXIT_SUCCESS;
}

View File

@ -33,7 +33,7 @@
#include <avahi-client/client.h>
#include <avahi-client/publish.h>
#include "err.h"
#include "logger.h"
#include "mdns_avahi.h"

View File

@ -29,7 +29,7 @@
#include <stdint.h>
#include <limits.h>
#include "err.h"
#include "logger.h"
#include "misc.h"

View File

@ -39,11 +39,13 @@
#include <sys/stat.h>
#include "err.h"
#include "logger.h"
#include "ff-dbstruct.h"
#include <FLAC/metadata.h>
#define TRUE ((1 == 1))
#define FALSE (!TRUE)
#define GET_VORBIS_COMMENT(comment, name, len) (char*) \
(((strncasecmp(name, (char*)(comment).entry, strlen(name)) == 0) && \

View File

@ -30,9 +30,13 @@
#include <string.h>
#include <taglib/tag_c.h>
#include "err.h"
#include "logger.h"
#include "ff-dbstruct.h"
#define TRUE ((1 == 1))
#define FALSE (!TRUE)
/**
* scan a musepack file for metainfo.
*

View File

@ -33,9 +33,12 @@
#include <sys/types.h>
#include <unistd.h>
#include "err.h"
#include "logger.h"
#include "ff-dbstruct.h"
#define TRUE ((1 == 1))
#define FALSE (!TRUE)
typedef struct tag_wma_guidlist {
char *name;
char *guid;

View File

@ -17,7 +17,7 @@
#include <string.h>
#include <time.h>
#include "err.h"
#include "logger.h"
extern int db_sql_escape(char *buffer, int *size, char *fmt, ...);

View File

@ -39,7 +39,7 @@
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include "err.h"
#include "logger.h"
#include "conffile.h"
#include "ff-dbstruct.h"
#include "transcode.h"