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