Add logger configuration options.
authorW. Trevor King <wking@drexel.edu>
Mon, 14 Jun 2010 13:48:17 +0000 (09:48 -0400)
committerW. Trevor King <wking@drexel.edu>
Mon, 14 Jun 2010 13:48:17 +0000 (09:48 -0400)
hooke/config.py
hooke/hooke.py
hooke/plugin/config.py

index 66f0b4ced67e00de44998636d7e8de5d014ec07b..5f9e91942cb48fccacd7392a35436f5992d382e5 100644 (file)
@@ -69,9 +69,11 @@ class Setting (object):
             if self.wrap == True:
                 if wrapper == None:
                     wrapper = textwrap.TextWrapper(
-                        initial_indent="# ",
-                        subsequent_indent="# ")
+                        initial_indent='# ',
+                        subsequent_indent='# ')
                 text = wrapper.fill(text)
+            else:
+                text = '# ' + '\n# '.join(text.splitlines())
             fp.write(text.rstrip()+'\n')
         if self.is_section():
             fp.write("[%s]\n" % self.section)
@@ -80,52 +82,32 @@ class Setting (object):
                                     str(value).replace('\n', '\n\t')))
 
 DEFAULT_SETTINGS = [
-    Setting('display', help='Control display appearance: colour, ???, etc.'),
-    Setting('display', 'colour_ext', 'None', help=None),
-    Setting('display', 'colour_ret', 'None', help=None),
-    Setting('display', 'ext', '1', help=None),
-    Setting('display', 'ret', '1', help=None),
-
-    Setting('display', 'correct', '1', help=None),
-    Setting('display', 'colout_correct', 'None', help=None),
-    Setting('display', 'contact_point', '0', help=None),
-    Setting('display', 'medfilt', '0', help=None),
-
-    Setting('display', 'xaxes', '0', help=None),
-    Setting('display', 'yaxes', '0', help=None),
-    Setting('display', 'flatten', '1', help=None),
-
-    Setting('conditions', 'temperature', '301', help=None),
-
-    Setting('fitting', 'auto_fit_points', '50', help=None),
-    Setting('fitting', 'auto_slope_span', '20', help=None),
-    Setting('fitting', 'auto_delta_force', '1-', help=None),
-    Setting('fitting', 'auto_fit_nm', '5', help=None),
-    Setting('fitting', 'auto_min_p', '0.005', help=None),
-    Setting('fitting', 'auto_max_p', '10', help=None),
-
-    Setting('?', 'baseline_clicks', '0', help=None),
-    Setting('fitting', 'auto_left_baseline', '20', help=None),
-    Setting('fitting', 'auto_right_baseline', '20', help=None),
-    Setting('fitting', 'force_multiplier', '1', help=None),
-    
-    Setting('display', 'fc_showphase', '0', help=None),
-    Setting('display', 'fc_showimposed', '0', help=None),
-    Setting('display', 'fc_interesting', '0', help=None),
-    Setting('?', 'tccd_threshold', '0', help=None),
-    Setting('?', 'tccd_coincident', '0', help=None),
-    Setting('display', '', '', help=None),
-    Setting('display', '', '', help=None),
-
-    Setting('filesystem', 'filterindex', '0', help=None),
-    Setting('filesystem', 'filters',
-            "Playlist files (*.hkp)|*.hkp|Text files (*.txt)|*.txt|All files (*.*)|*.*')",
-            help=None),
-    Setting('filesystem', 'workdir', 'test',
-            help='\n'.join(['# Substitute your work directory',
-                            '#workdir = D:\hooke']),
-            wrap=False),
-    Setting('filesystem', 'playlist', 'test.hkp', help=None),
+    Setting('conditions', help='Default environmental conditions in case they are not specified in the force curve data.'),
+    Setting('conditions', 'temperature', '301', help='Temperature in Kelvin'),
+    # Logging settings
+    Setting('loggers', help='Configure loggers, see\nhttp://docs.python.org/library/logging.html#configuration-file-format', wrap=False),
+    Setting('loggers', 'keys', 'root, hooke', help='Hooke only uses the hooke logger, but other included modules may also use logging and you can configure their loggers here as well.'),
+    Setting('handlers', help='Configure log handlers, see\nhttp://docs.python.org/library/logging.html#configuration-file-format', wrap=False),
+    Setting('handlers', 'keys', 'hand1'),
+    Setting('formatters', help='Configure log formatters, see\nhttp://docs.python.org/library/logging.html#configuration-file-format', wrap=False),
+    Setting('formatters', 'keys', 'form1'),
+    Setting('logger_root', help='Configure the root logger, see\nhttp://docs.python.org/library/logging.html#configuration-file-format', wrap=False),
+    Setting('logger_root', 'level', 'NOTSET'),
+    Setting('logger_root', 'handlers', 'hand1'),
+    Setting('logger_hooke', help='Configure the hooke logger, see\nhttp://docs.python.org/library/logging.html#configuration-file-format', wrap=False),
+    Setting('logger_hooke', 'level', 'DEBUG'),
+    Setting('logger_hooke', 'handlers', 'hand1', help='No specific handlers here, just propagate up to the root logger'),
+    Setting('logger_hooke', 'propagate', '0'),
+    Setting('logger_hooke', 'qualname', 'hooke'),
+    Setting('handler_hand1', help='Configure the default log handler, see\nhttp://docs.python.org/library/logging.html#configuration-file-format', wrap=False),
+    Setting('handler_hand1', 'class', 'StreamHandler'),
+    Setting('handler_hand1', 'level', 'NOTSET'),
+    Setting('handler_hand1', 'formatter', 'form1'),
+    Setting('handler_hand1', 'args', '(sys.stderr,)'),
+    Setting('formatter_form1', help='Configure the default log formatter, see\nhttp://docs.python.org/library/logging.html#configuration-file-format', wrap=False),
+    Setting('formatter_form1', 'format', '%(asctime)s %(levelname)s %(message)s'),
+    Setting('formatter_form1', 'datefmt', '', help='Leave blank for ISO8601, e.g. "2003-01-23 00:29:50,411".'),
+    Setting('formatter_form1', 'class', 'logging.Formatter'),
     ]
 
 def get_setting(settings, match):
index 6b4975738849b45fb0d89e3c525d5652f6e376f9..ccea160687edaa714e5bbbd15204224682104a12 100644 (file)
@@ -54,10 +54,13 @@ if False: # Queue pickle error debugging code
         feed(buffer, notempty, s, writelock, close)
     multiprocessing.queues.Queue._feed = staticmethod(new_feed)
 
+import logging
+import logging.config
 import multiprocessing
 import optparse
 import os.path
 import unittest
+import StringIO
 import sys
 
 from . import engine as engine
@@ -81,13 +84,22 @@ class Hooke (object):
                 default_settings=default_settings)
             config.read()
         self.config = config
+        self.load_log()
         self.load_plugins()
         self.load_drivers()
         self.load_ui()
         self.command = engine.CommandEngine()
-
         self.playlists = playlist.NoteIndexList()
 
+    def load_log(self):
+        config_file = StringIO.StringIO()
+        self.config.write(config_file)
+        x = config_file.getvalue()
+        logging.config.fileConfig(StringIO.StringIO(config_file.getvalue()))
+        # Don't attach the logger because it contains an unpicklable
+        # thread.lock.  Instead, grab it directly every time you need it.
+        #self.log = logging.getLogger('hooke')
+
     def load_plugins(self):
         self.plugins = plugin_mod.load_graph(
             plugin_mod.PLUGIN_GRAPH, self.config, include_section='plugins')
index 82ba03844a013160a603796880269875ba5e8499..21fd56ae2264f0ecdc6c0e8ad18efbeadab2e1d8 100644 (file)
@@ -87,8 +87,10 @@ class SetCommand (Command):
     def _run(self, hooke, inqueue, outqueue, params):
        hooke.config.set(params['section'], params['option'], params['value'])
         # push config changes
+        hooke.load_log()
         hooke.load_plugins()
         hooke.load_drivers()
+        hooke.load_ui()  # for post-HookeRunner Hooke return.
         # notify UI to update config
         outqueue.put(ReloadUserInterfaceConfig(hooke.config))