--- getstream-old/getstream.c 2009-08-01 12:01:35.000000000 +0200 +++ getstream/getstream.c 2010-01-17 11:19:21.000000000 +0100 @@ -98,7 +98,7 @@ static void usage(void ) { - fprintf(stderr, "-c -d -t \n"); + fprintf(stderr, "-c -d -t -l \n"); exit(-1); } @@ -110,8 +110,10 @@ int timeout=0; GList *al; struct config_s *config=NULL; + + logwrite_init(); - while((ch=getopt(argc, argv, "c:dt:")) != -1) { + while((ch=getopt(argc, argv, "c:dt:l:")) != -1) { switch(ch) { case 'c': config=readconfig(optarg); @@ -124,6 +126,10 @@ case 't': timeout=strtol(optarg, NULL, 10); break; + case 'l': + if (logwrite_set_output(optarg) == 0) + exit(1); + break; default: usage(); break; diff -u getstream-old/getstream.h getstream/getstream.h --- getstream-old/getstream.h 2009-08-01 12:01:35.000000000 +0200 +++ getstream/getstream.h 2010-01-17 11:19:37.000000000 +0100 @@ -403,8 +403,10 @@ * * */ +void logwrite_init(); void logwrite_inc_level(void ); void logwrite(int level, const char *format, ...); +int logwrite_set_output(const char * file); enum { LOG_ERROR, --- getstream-old/logging.c 2009-08-01 12:01:35.000000000 +0200 +++ getstream/logging.c 2010-01-17 11:23:11.000000000 +0100 @@ -1,12 +1,20 @@ #include #include #include +#include +#include #include #include #include "getstream.h" int loglevel=LOG_ERROR; +static FILE * logfile; + +void logwrite_init() { + if (!logfile) + logfile = stdout; +} void logwrite_inc_level() { loglevel++; @@ -32,8 +40,20 @@ strftime(timedate, sizeof(timedate), "%Y-%m-%d %H:%M:%S", tm); - printf("%s.%03d %s\n", + fprintf(logfile, "%s.%03d %s\n", timedate, (int) tv.tv_usec/1000, logbuffer); + + fflush(logfile); } + +int logwrite_set_output(const char * file) { + logfile = fopen(file, "a"); + if (logfile == NULL) { + fprintf(stderr, "Log file open failed: %s\n", strerror(errno)); + return 0; + } + return 1; +} +