Author: duncan
Date: Sun Jun  3 12:12:55 2007
New Revision: 9643

Modified:
   branches/rel-1/freevo/freevo_config.py
   branches/rel-1/freevo/local_conf.py.example
   branches/rel-1/freevo/src/config.py

Log:
Added python logging.
This generates a duplicate log at the moment but this will change


Modified: branches/rel-1/freevo/freevo_config.py
==============================================================================
--- branches/rel-1/freevo/freevo_config.py      (original)
+++ branches/rel-1/freevo/freevo_config.py      Sun Jun  3 12:12:55 2007
@@ -276,6 +276,7 @@
      ''' ),
     (5.20,
      '''Added PERSONAL_WWW_PAGE config item to allow private web pages in the 
webserver
+        Added LOGGING, can be one of CRITICAL, ERROR, WARNING, INFO, DEBUG
         Changed VIDEO_INTERLACING to VIDEO_DEINTERLACE to be more consistent 
with autovars
      ''' ),
 ]
@@ -1603,9 +1604,9 @@
 # a program matching the name, day of week etc should still be considered a
 # favorite. For example a favorite has a start time of 21.00, but the program
 # has been brought forward by the broadcaster by 10 minutes to 20.50, with
-# a margin of less than 10 this program will not be recorded as the start time 
+# a margin of less than 10 this program will not be recorded as the start time
 # is outside the margin. But if the margin is set at 10 minutes or greater this
-# program will be considered a favorite and recorded. Probably about 45 
minutes 
+# program will be considered a favorite and recorded. Probably about 45 minutes
 # is the best bet, better a false positive than a false negative.
 TV_RECORD_FAVORITE_MARGIN = 45
 
@@ -1962,3 +1963,6 @@
 
 TIME_DEBUG = 0
 
+# The default logging level
+# can be one of CRITICAL (FATAL), ERROR, WARNING (WARN), INFO, DEBUG, NOTSET
+LOGGING = logging.WARNING

Modified: branches/rel-1/freevo/local_conf.py.example
==============================================================================
--- branches/rel-1/freevo/local_conf.py.example (original)
+++ branches/rel-1/freevo/local_conf.py.example Sun Jun  3 12:12:55 2007
@@ -1058,7 +1058,7 @@
 # MPLAYER_VF_INTERLACED  = 'pp=de/fd'
 # MPLAYER_VF_PROGRESSIVE = 'pp=de'
 #
-# For the autodetect TOP/BOTTOM field first in mplayer 
+# For the autodetect TOP/BOTTOM field first in mplayer
 # (if this feature present in mplayer)
 # MPLAYER_HAS_FIELD_DOMINANCE = 1
 #
@@ -1242,9 +1242,9 @@
 # a program matching the name, day of week etc should still be considered a
 # favorite. For example a favorite has a start time of 21.00, but the program
 # has been brought forward by the broadcaster by 10 minutes to 20.50, with
-# a margin of less than 10 this program will not be recorded as the start time 
+# a margin of less than 10 this program will not be recorded as the start time
 # is outside the margin. But if the margin is set at 10 minutes or greater this
-# program will be considered a favorite and recorded. Probably about 45 
minutes 
+# program will be considered a favorite and recorded. Probably about 45 minutes
 # is the best bet, better a false positive than a false negative.
 # TV_RECORD_FAVORITE_MARGIN = 45
 

Modified: branches/rel-1/freevo/src/config.py
==============================================================================
--- branches/rel-1/freevo/src/config.py (original)
+++ branches/rel-1/freevo/src/config.py Sun Jun  3 12:12:55 2007
@@ -48,6 +48,8 @@
 import __builtin__
 import version
 import locale
+import logging
+
 
 locale.setlocale(locale.LC_TIME,'')
 
@@ -58,6 +60,10 @@
 
 VERSION = version.__version__
 
+LOGGING = logging.WARNING
+global loggerisinitialised
+loggerisinitialised = False
+
 # For Internationalization purpose
 # an exception is raised with Python 2.1 if LANG is unavailable.
 import gettext
@@ -92,7 +98,12 @@
         self.logtype = logtype
         appname = os.path.splitext(os.path.basename(sys.argv[0]))[0]
         logfile = '%s/%s-%s.log' % (LOGDIR, appname, os.getuid())
+        logging.basicConfig(level=LOGGING, \
+            #datefmt='%a, %H:%M:%S',
+            format='%(asctime)s %(levelname)-8s %(message)s', \
+            filename=logfile+'.log', filemode='a')
         self.logfile = logfile
+        self.isinitialised = False
         try:
             self.fp = open(logfile, 'a')
         except IOError:
@@ -100,6 +111,9 @@
             self.fp = open('/dev/null','a')
         self.softspace = 0
 
+    def initialised(self):
+        self.isinitialised = True
+
     def write(self, msg):
         global DEBUG_STDOUT
         if isinstance(msg, unicode):
@@ -119,7 +133,9 @@
         pass
 
     def close(self):
-        pass
+        logging.info('-' * 80)
+        logging.info('Log closed')
+        logging.info('=' * 80)
 
 
 class VideoGroup:
@@ -278,16 +294,14 @@
     sys.stdout.log('Freevo (%s) start at %s\n' % (VERSION, ts))
     sys.stdout.log('-' * 79 + '\n')
 
-def _stack_function_(message=None, limit=None):
+def _stack_function_(message='', limit=None):
     import traceback
-    if message:
-        print '%s' % (message)
     stack = traceback.extract_stack()
     if stack:
         if limit:
-            print '*** %s' % ('*** 
'.join(traceback.format_list(stack[-limit-1:-1])))
+            logging.debug('%s\n*** %s' % (message, '*** 
'.join(traceback.format_list(stack[-limit-1:-1]))))
         else:
-            print '*** %s' % ('*** '.join(traceback.format_list(stack)[0:-1]))
+            logging.debug('%s\n*** %s' % (message, '*** 
'.join(traceback.format_list(stack)[0:-1])))
 
 def _debug_function_(s, level=1):
     if DEBUG < level:
@@ -300,6 +314,16 @@
         s = '%s (%s): %s' % (where[0][where[0].rfind('/')+1:], where[1], s)
         # print debug message
         print s
+        if level <= -3:
+            logging.critical(s)
+        elif level == -2:
+            logging.error(s)
+        elif level == -1:
+            logging.warning(s)
+        elif level == 0:
+            logging.info(s)
+        else:
+            logging.debug(s)
     except UnicodeEncodeError:
         print "_debug_ failed."
 
@@ -491,7 +515,7 @@
             CONFIG_VERSION
         except NameError:
             print
-            print 'Error: your local_config.py file has no version information'
+            print 'Error: your local_conf.py file has no version information'
             print 'Please check freevo_config.py for changes and set 
CONFIG_VERSION'
             print 'in %s to %s' % (overridefile, LOCAL_CONF_VERSION)
             print
@@ -501,7 +525,7 @@
            int(str(LOCAL_CONF_VERSION).split('.')[0]):
             print
             print 'Error: The version information in freevo_config.py doesn\'t'
-            print 'match the version in your local_config.py.'
+            print 'match the version in your local_conf.py.'
             print 'Please check freevo_config.py for changes and set 
CONFIG_VERSION'
             print 'in %s to %s' % (overridefile, LOCAL_CONF_VERSION)
             print_config_changes(LOCAL_CONF_VERSION, CONFIG_VERSION,
@@ -511,7 +535,7 @@
         if int(str(CONFIG_VERSION).split('.')[1]) != \
            int(str(LOCAL_CONF_VERSION).split('.')[1]):
             print
-            print 'Warning: freevo_config.py was changed, please check 
local_config.py'
+            print 'Warning: freevo_config.py was changed, please check 
local_conf.py'
             print_config_changes(LOCAL_CONF_VERSION, CONFIG_VERSION,
                                  LOCAL_CONF_CHANGES)
         break
@@ -532,7 +556,15 @@
 
 
 if not HELPER:
-    _debug_('Logging to %s' % sys.stdout.logfile)
+    logging.getLogger('').setLevel(LOGGING)
+
+    if not loggerisinitialised:
+        loggerisinitialised = True
+        import freevo.version, freevo.revision
+        logging.warn('=' * 80)
+        logging.warn('Log opened for Freevo %s r%s' % 
(freevo.version.__version__, freevo.revision.__revision__))
+        logging.warn('-' * 80)
+        _debug_('Logging to %s' % sys.stdout.logfile)
 
 #
 # force fullscreen when freevo is it's own windowmanager

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to