Index: py-tcpmultiplexer/TCPMultiplexer.py
===================================================================
--- py-tcpmultiplexer/TCPMultiplexer.py	(revision 330)
+++ py-tcpmultiplexer/TCPMultiplexer.py	(revision 331)
@@ -12,4 +12,5 @@
 import argparse
 import logging
+import logging.handlers
 import os
 import socket
@@ -25,4 +26,5 @@
 DEFAULT_DOCUMENTROOT = './htdocs'
 DEFAULT_TIMEOUT = None
+DEFAULT_LOGFILE = 'py-tcpmultiplexer.log'
 
 
@@ -44,5 +46,12 @@
 recv_timeout = None
 
-logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+logger = logging.getLogger(__name__)
+logger.setLevel(logging.INFO)
+formatter = logging.Formatter('%(asctime)s - %(threadName)s - %(levelname)s - %(message)s')
+
+ch = logging.StreamHandler()
+ch.setFormatter(formatter)
+
+logger.addHandler(ch)
 
 class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
@@ -106,5 +115,4 @@
   """ Fetch the DATA from the WAV or MJPEG Stream """
   global running, dataheader, urlheader, urldata, stream_running, recv_timeout
-  logger = logging.getLogger('recv_id=' + urlid)
   # Fill buffers if needed
   logger.info("Starting thread '%s' (%s)", url, urlid)
@@ -178,5 +186,5 @@
         for key in urldata[urlid].keys():
           urldata[urlid][key].append(data)
-    except IOError, e:
+    except (urllib2.URLError, IOError) as e:
       #Enforce a connection reset
       logger.warning("URL reset '%s' (%s)", url, e)
@@ -191,4 +199,5 @@
   parser.add_argument('--host', dest='host', default=DEFAULT_HOST, help='Listen to IP [default: %s]' % DEFAULT_HOST)
   parser.add_argument('--port', dest='port', default=DEFAULT_PORT, type=int, help='Listen to PORT [default: %s]' % DEFAULT_PORT)
+  parser.add_argument('--logfile', dest='logfile', default=DEFAULT_LOGFILE, help='File to write logfiles to [default: %s]' % DEFAULT_LOGFILE)
   parser.add_argument('--timeout', dest='timeout', default=DEFAULT_TIMEOUT, type=int, help='Default socket timeout [default: %s]' % DEFAULT_TIMEOUT)
   parser.add_argument('--stream-cfg', dest='stream_cfg', default=DEFAULT_CONFIG, help='YAML Stream configuration [default: %s]' % DEFAULT_CONFIG)
@@ -196,10 +205,16 @@
   args = parser.parse_args()
 
+  # Add file logger
+  ch = logging.handlers.WatchedFileHandler(args.logfile)
+  ch.setFormatter(formatter)
+  logger.addHandler(ch)
+  
   document_root = os.path.abspath(os.path.join(os.path.dirname(__file__),args.document_root))
-  logging.info("Serving '/htdocs' from document_root '%s'", document_root)
+  logger.info("Serving '/htdocs' from document_root '%s'", document_root)
 
   # Set the timeout
-  logging.info("Changing socket timeout from '%s' to '%s'", socket.getdefaulttimeout(), args.timeout)
+  logger.info("Changing socket timeout from '%s' to '%s'", socket.getdefaulttimeout(), args.timeout)
   recv_timeout = args.timeout
+
 
   # Inport streams
@@ -209,5 +224,5 @@
     streams.update(yaml.load(open(args.stream_cfg)))
   except (ImportError, IOError) as e:
-    logging.warning("Stream config file '%s' not readable or parsable (%s)", args.stream_cfg, e)
+    logger.warning("Stream config file '%s' not readable or parsable (%s)", args.stream_cfg, e)
 
 
@@ -220,5 +235,5 @@
         break
       except IOError, e:
-        logging.warning('For conection %s:%s to become available (%s)', args.host, args.port , e)
+        logger.warning('For conection %s:%s to become available (%s)', args.host, args.port , e)
         time.sleep(1)
   except KeyboardInterrupt:
@@ -226,5 +241,5 @@
 
   for urlid, url in streams.iteritems():
-    recv_threads.append(threading.Thread(target=get_data, args=(url,urlid)))
+    recv_threads.append(threading.Thread(name=urlid, target=get_data, args=(url,urlid)))
     recv_threads[-1].setDaemon(True)
     recv_threads[-1].start()
@@ -233,11 +248,11 @@
   # interrupt the program with Ctrl-C
   try:
-    logging.info('Serving at %s:%s', args.host, args.port)
+    logger.info('Serving at %s:%s', args.host, args.port)
     server.serve_forever()
   except KeyboardInterrupt, IOError:
-    logging.info('Shutting down, please wait...')
+    logger.info('Shutting down, please wait...')
     running = False
     server.shutdown()
     [thread.join() for thread in recv_threads]
-    logging.info('All done, good bye!')
-
+    logger.info('All done, good bye!')
+
