Massive rewrite (v 0.6) to base everything on Cython and revamped pypiezo.
[calibcant.git] / calibcant / __init__.py
index 34670a523b8f7b8cae3cbffb73ac16077fdc9d9a..1b1bd7313ba871260965ee2869e797583e207091 100644 (file)
@@ -1,24 +1,67 @@
 # calibcant - tools for thermally calibrating AFM cantilevers
 #
-# Copyright (C) 2007,2008, William Trevor King
+# Copyright (C) 2008-2011 W. Trevor King <wking@drexel.edu>
 #
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 3 of the
-# License, or (at your option) any later version.
+# This file is part of calibcant.
 #
-# This program 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 General Public License for more details.
+# 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.
 #
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
+# 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.
 #
-# The author may be contacted at <wking@drexel.edu> on the Internet, or
-# write to Trevor King, Drexel University, Physics Dept., 3141 Chestnut St.,
-# Philadelphia PA 19104, USA.
+# You should have received a copy of the GNU Lesser General Public
+# License along with calibcant.  If not, see
+# <http://www.gnu.org/licenses/>.
 
-from .common import VERSION
+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)