Rename from tempcontrol to pypid (now that I'm moving to a more general framework).
[pypid.git] / pypid / __init__.py
1 # Copyright (C) 2008-2011 W. Trevor King <wking@drexel.edu>
2 #
3 # This file is part of pypid.
4 #
5 # pypid is free software: you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation, either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # pypid is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with pypid.  If not, see
17 # <http://www.gnu.org/licenses/>.
18
19 import logging as _logging
20
21
22 __version__ = '0.3'
23
24
25 LOG = _logging.getLogger('pypid')
26 "Temperature-control logger"
27
28 #LOG.setLevel(_logging.WARN)
29 LOG.setLevel(_logging.DEBUG)
30 _formatter = _logging.Formatter(
31     '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
32
33 _stream_handler = _logging.StreamHandler()
34 _stream_handler.setLevel(_logging.DEBUG)
35 _stream_handler.setFormatter(_formatter)
36 LOG.addHandler(_stream_handler)
37
38 _syslog_handler = None
39
40
41 def _set_handler(name='stream'):
42     if name == 'syslog':
43         if not _syslog_handler:
44             _syslog_handler = _logging_handlers.SysLogHandler()
45             _syslog_handler.setLevel(_logging.DEBUG)
46         LOG.handlers = [_syslog_handler]
47     elif name == 'stream':
48         LOG.handlers = [_stream_handler]
49     else:
50         raise ValueError(name)
51     LOG.info('setup logging handler: %s' % name)