1 # calibcant - tools for thermally calibrating AFM cantilevers
3 # Copyright (C) 2008-2011 W. Trevor King <wking@drexel.edu>
5 # This file is part of calibcant.
7 # calibcant is free software: you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation, either
10 # version 3 of the License, or (at your option) any later version.
12 # calibcant is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with calibcant. If not, see
19 # <http://www.gnu.org/licenses/>.
21 import logging as _logging
22 import logging.handlers as _logging_handlers
28 LOG = _logging.getLogger('calibcant')
31 LOG.setLevel(_logging.WARN)
32 _formatter = _logging.Formatter(
33 '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
35 _stream_handler = _logging.StreamHandler()
36 _stream_handler.setLevel(_logging.DEBUG)
37 _stream_handler.setFormatter(_formatter)
38 LOG.addHandler(_stream_handler)
40 _syslog_handler = None
43 from .config import _BaseConfig
44 from .config import find_base_config as _find_base_config
47 def setup_base_config(config):
48 global base_config, _syslog_handler
51 LOG.setLevel(base_config['log-level'])
53 if base_config['syslog']:
54 if not _syslog_handler:
55 _syslog_handler = _logging_handlers.SysLogHandler()
56 _syslog_handler.setLevel(_logging.DEBUG)
57 LOG.handlers = [_syslog_handler]
59 LOG.handlers = [_stream_handler]
61 LOG.info('setup base_config:\n%s' % config.dump())
63 def clear_base_config():
64 setup_base_config(_BaseConfig())
66 base_config = _find_base_config()
67 setup_base_config(base_config)