comparison src/cagou/core/logging_setter.py @ 15:56838ad5c84b

files reorganisation, cagou is now launched with python2 cagou.py in src/
author Goffi <goffi@goffi.org>
date Sat, 09 Jul 2016 17:24:01 +0200
parents src/logging_setter.py@5ebe1592a05a
children
comparison
equal deleted inserted replaced
14:21a432afd06d 15:56838ad5c84b
1 #!/usr//bin/env python2
2 # -*- coding: utf-8 -*-
3
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
5 # Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org)
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program 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 Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 CONF_KIVY_LEVEL = 'log_kivy_level'
21
22 def set_logging():
23 from constants import Const as C
24 from sat.core import log_config
25 log_config.satConfigure(C.LOG_BACKEND_STANDARD, C)
26
27 import config
28 kivy_level = config.getConfig(C.CONFIG_SECTION, CONF_KIVY_LEVEL, 'follow').upper()
29
30 # kivy handles its own loggers, we don't want that!
31 import logging
32 root_logger = logging.root
33 kivy_logger = logging.getLogger('kivy')
34 ori_addHandler = kivy_logger.addHandler
35 kivy_logger.addHandler = lambda dummy: None
36 ori_setLevel = kivy_logger.setLevel
37 if kivy_level == 'FOLLOW':
38 # level is following SàT level
39 kivy_logger.setLevel = lambda level: None
40 elif kivy_level == 'KIVY':
41 # level will be set by Kivy according to its own conf
42 pass
43 elif kivy_level in C.LOG_LEVELS:
44 kivy_logger.setLevel(kivy_level)
45 kivy_logger.setLevel = lambda level: None
46 else:
47 raise ValueError(u"Unknown value for {name}: {value}".format(name=CONF_KIVY_LEVEL, value=kivy_level))
48
49 # during import kivy set its logging stuff
50 import kivy
51 kivy # to avoid pyflakes warning
52
53 # we want to separate kivy logs from other logs
54 logging.root = root_logger
55 import sys
56 from kivy import logger
57 sys.stderr = logger.previous_stderr
58
59 # we restore original methods
60 kivy_logger.addHandler = ori_addHandler
61 kivy_logger.setLevel = ori_setLevel