comparison src/core/log_config.py @ 2089:0931b5a6213c

core, quick_frontends: android compatibility hacks: a couple of hacks have been used so backend can be launched on android using kivy - config file (sat.conf) is been read on a specific dir, using a detection of Cagou domains in constants.py - fixed crash when using sys.stdout.isatty in log_config.py - Q&D fix for logging encoding issue on android - when android is detected, the path/pattern to load plugins is modified - SRV is not working at the moment on android. If the platform is detected, the host is used directly with default port. A hosts_dir configuration can be used in [android] section to map a specific ip to a host - getRepositoryData in tools/utils return constant string on android. Proper repository data need to be copied during package building. - [quick app] more robust failure handling on asyncConnect error - [quick chat] default to utf-8 when getlocale doesn't return the actual locale.
author Goffi <goffi@goffi.org>
date Sun, 04 Dec 2016 18:16:48 +0100
parents 7f053e1f0b67
children 8b37a62336c3
comparison
equal deleted inserted replaced
2088:c02f96756d5c 2089:0931b5a6213c
45 45
46 def configureColors(self, colors, force_colors, levels_taints_dict): 46 def configureColors(self, colors, force_colors, levels_taints_dict):
47 super(ConfigureBasic, self).configureColors(colors, force_colors, levels_taints_dict) 47 super(ConfigureBasic, self).configureColors(colors, force_colors, levels_taints_dict)
48 if colors: 48 if colors:
49 import sys 49 import sys
50 if force_colors or sys.stdout.isatty(): # FIXME: isatty should be tested on each handler, not globaly 50 try:
51 isatty = sys.stdout.isatty()
52 except AttributeError:
53 isatty = False
54 if force_colors or isatty: # FIXME: isatty should be tested on each handler, not globaly
51 # we need colors 55 # we need colors
52 log.Logger.post_treat = lambda logger, level, message: self.ansiColors(level, message) 56 log.Logger.post_treat = lambda logger, level, message: self.ansiColors(level, message)
53 elif force_colors: 57 elif force_colors:
54 raise ValueError("force_colors can't be used if colors is False") 58 raise ValueError("force_colors can't be used if colors is False")
55 59
260 self.level = level 264 self.level = level
261 265
262 def configureFormat(self, fmt): 266 def configureFormat(self, fmt):
263 super(ConfigureStandard, self).configureFormat(fmt) 267 super(ConfigureStandard, self).configureFormat(fmt)
264 import logging 268 import logging
269 import sys
265 270
266 class SatFormatter(logging.Formatter): 271 class SatFormatter(logging.Formatter):
267 u"""Formatter which manage SàT specificities""" 272 u"""Formatter which manage SàT specificities"""
268 _format = fmt 273 _format = fmt
269 _with_profile = '%(profile)s' in fmt 274 _with_profile = '%(profile)s' in fmt
285 else: 290 else:
286 record.color_start = record.color_end = '' 291 record.color_start = record.color_end = ''
287 s = super(SatFormatter, self).format(record) 292 s = super(SatFormatter, self).format(record)
288 if do_color: 293 if do_color:
289 s = ConfigureStandard.ansiColors(record.levelname, s) 294 s = ConfigureStandard.ansiColors(record.levelname, s)
290 return s 295 if sys.platform == "android":
296 # FIXME: dirty hack to workaround android encoding issue on log
297 # need to be fixed properly
298 return s.encode('ascii', 'ignore')
299 else:
300 return s
291 301
292 self.formatterClass = SatFormatter 302 self.formatterClass = SatFormatter
293 303
294 def configureOutput(self, output): 304 def configureOutput(self, output):
295 self.manageOutputs(output) 305 self.manageOutputs(output)