Added more complex setup of logging
authorJason Michalski <armooo@armooo.net>
Mon, 7 Apr 2008 04:41:58 +0000 (6 23:41 -0500)
committerJason Michalski <armooo@armooo.net>
Mon, 7 Apr 2008 04:41:58 +0000 (6 23:41 -0500)
See the python logging documation.

pyTivo.py

index dbe4af5..30725f7 100755 (executable)
--- a/pyTivo.py
+++ b/pyTivo.py
@@ -1,12 +1,30 @@
 #!/usr/bin/env python
 
 import logging
-logging.basicConfig(level=logging.DEBUG)
-
+import logging.config
+import os
+import ConfigParser
 import beacon, httpserver, os, sys
 import config
 from plugin import GetPlugin
 
+def init_logging():
+    config.config_files
+    p = os.path.dirname(__file__)
+
+    if config.config.has_section('loggers') and\
+      config.config.has_section('handlers') and\
+      config.config.has_section('formatters'):
+
+        logging.config.fileConfig(config.config_files)
+
+    elif config.getDebug(0):
+        logging.basicConfig(level=logging.DEBUG)
+    else:
+        logging.basicConfig(level=logging.INFO)
+
+init_logging()
+
 port = config.getPort()
 
 httpd = httpserver.TivoHTTPServer(('', int(port)), httpserver.TivoHTTPHandler)