diff --git a/.gitignore b/.gitignore
index 70bce91..42ef55e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,5 +8,6 @@ core*
 *.rej
 tsdecode
 getstream
-
+getstream.conf
+gs.sh
 !.gitignore
diff --git a/Makefile b/Makefile
index 345a635..47cc29d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,9 @@
 CC=gcc
-CFLAGS=-O0 -g -Wall  -I. -I/usr/include/glib-2.0/ -I/usr/lib/glib-2.0/include/
+ifdef NO_DEBUG
+    CFLAGS=-O2 -Wall  -I. -I/usr/include/glib-2.0/ -I/usr/lib/glib-2.0/include/
+else
+    CFLAGS=-O0 -g -Wall  -I. -I/usr/include/glib-2.0/ -I/usr/lib/glib-2.0/include/
+endif
 LDFLAGS=-levent -lglib-2.0 -lpthread
 OBJ-getstream=getstream.o fe.o crc32.o \
 	libhttp.o libconf.o config.o util.o logging.o \
diff --git a/getstream.c b/getstream.c
index b56fa3e..45c5502 100644
--- a/getstream.c
+++ b/getstream.c
@@ -98,7 +98,7 @@ static void terminate_init(int timeout) {
 
 
 static void usage(void ) {
-	fprintf(stderr, "-c <config file> -d -t <timeout>\n");
+	fprintf(stderr, "-c <config file> -d -t <timeout> -f <logfile>\n");
 	exit(-1);
 }
 
@@ -110,8 +110,7 @@ int main(int argc, char **argv) {
 	int			timeout=0;
 	GList			*al;
 	struct config_s		*config=NULL;
-
-	while((ch=getopt(argc, argv, "c:dt:")) != -1) {
+	while((ch=getopt(argc, argv, "c:dt:f:")) != -1) {
 		switch(ch) {
 			case 'c':
 				config=readconfig(optarg);
@@ -124,6 +123,9 @@ int main(int argc, char **argv) {
 			case 't':
 				timeout=strtol(optarg, NULL, 10);
 				break;
+			case 'f':
+				preparelogfile(optarg);
+				break;
 			default:
 				usage();
 				break;
diff --git a/getstream.h b/getstream.h
index 5aec52c..6226b10 100644
--- a/getstream.h
+++ b/getstream.h
@@ -165,6 +165,7 @@ enum {
  */
 
 extern int loglevel;
+//extern int uselogfile;
 
 #define MAX_MCAST_PAYLOAD	(1500-40)
 #define TS_PACKET_SIZE		188
diff --git a/logging.c b/logging.c
index 3c62f16..91d3582 100644
--- a/logging.c
+++ b/logging.c
@@ -3,11 +3,22 @@
 #include <stdlib.h>
 #include <sys/param.h>
 #include <time.h>
-
+#include <fcntl.h>
 #include "getstream.h"
 
 int loglevel=LOG_ERROR;
-
+int uselogfile=0;
+FILE * lfd;
+void preparelogfile(char *file) {
+	lfd=fopen(file,"a");
+	if(lfd==NULL)
+	{
+		logwrite(LOG_ERROR,"error opening log file '%s' for write",file);
+		uselogfile=0;
+		return;
+	}
+	uselogfile=1;
+}
 void logwrite_inc_level() {
 	loglevel++;
 }
@@ -36,4 +47,11 @@ void logwrite(int level, const char *format, ...) {
 			timedate,
 			(int) tv.tv_usec/1000,
 			logbuffer);
+	if(uselogfile==1) {
+		fprintf(lfd,"%s.%03d %s\n",
+				timedate,
+				(int) tv.tv_usec/1000,
+				logbuffer);
+		fflush(lfd);
+	}
 }
