Massive rewrite (v 0.6) to base everything on Cython and revamped pypiezo.
[calibcant.git] / calibcant / __init__.py
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..1b1bd7313ba871260965ee2869e797583e207091 100644 (file)
@@ -0,0 +1,67 @@
+# calibcant - tools for thermally calibrating AFM cantilevers
+#
+# Copyright (C) 2008-2011 W. Trevor King <wking@drexel.edu>
+#
+# This file is part of calibcant.
+#
+# calibcant is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation, either
+# version 3 of the License, or (at your option) any later version.
+#
+# calibcant is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with calibcant.  If not, see
+# <http://www.gnu.org/licenses/>.
+
+import logging as _logging
+import logging.handlers as _logging_handlers
+
+
+__version__ = '0.4'
+
+
+LOG = _logging.getLogger('calibcant')
+"Calibcant logger"
+
+LOG.setLevel(_logging.WARN)
+_formatter = _logging.Formatter(
+    '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+
+_stream_handler = _logging.StreamHandler()
+_stream_handler.setLevel(_logging.DEBUG)
+_stream_handler.setFormatter(_formatter)
+LOG.addHandler(_stream_handler)
+
+_syslog_handler = None
+
+
+from .config import _BaseConfig
+from .config import find_base_config as _find_base_config
+
+
+def setup_base_config(config):
+    global base_config, _syslog_handler
+    base_config = config
+
+    LOG.setLevel(base_config['log-level']) 
+
+    if base_config['syslog']:
+        if not _syslog_handler:
+            _syslog_handler = _logging_handlers.SysLogHandler()
+            _syslog_handler.setLevel(_logging.DEBUG)
+        LOG.handlers = [_syslog_handler]
+    else:
+        LOG.handlers = [_stream_handler]
+
+    LOG.info('setup base_config:\n%s' % config.dump())
+
+def clear_base_config():
+    setup_base_config(_BaseConfig())
+
+base_config = _find_base_config()
+setup_base_config(base_config)