diff options
author | 2013-01-25 18:43:53 +0100 | |
---|---|---|
committer | 2013-01-25 18:43:53 +0100 | |
commit | 4b75ae96097741576f5dacd4a366119e56501700 (patch) | |
tree | cb9200229aa23fefbb396fac3b3b01cb263c78e9 /pyload.py | |
parent | refractored icons, + generation task (diff) | |
download | pyload-4b75ae96097741576f5dacd4a366119e56501700.tar.xz |
fallback when no system locale can be retrieved
Diffstat (limited to 'pyload.py')
-rwxr-xr-x | pyload.py | 24 |
1 files changed, 15 insertions, 9 deletions
@@ -500,15 +500,21 @@ class Core(object): def init_logger(self, level): console = logging.StreamHandler(sys.stdout) - # change current locale to default if it is not set - current_locale = locale.getlocale() - if current_locale == (None, None): - current_locale = locale.setlocale(locale.LC_ALL, '') - - # We use timeformat provided by locale when available - if current_locale != (None, None): - tfrm = locale.nl_langinfo(locale.D_FMT) + " " + locale.nl_langinfo(locale.T_FMT) - else: # normally this case should not be entered + # try to get a time formatting depending on system locale + tfrm = None + try: # change current locale to default if it is not set + current_locale = locale.getlocale() + if current_locale == (None, None): + current_locale = locale.setlocale(locale.LC_ALL, '') + + # We use timeformat provided by locale when available + if current_locale != (None, None): + tfrm = locale.nl_langinfo(locale.D_FMT) + " " + locale.nl_langinfo(locale.T_FMT) + except: # something did go wrong, locale is heavily platform dependant + pass + + # default formatting when no ne was obtained + if not tfrm: tfrm = "%d.%m.%Y %H:%M:%S" frm = logging.Formatter("%(asctime)s %(levelname)-8s %(message)s", tfrm) |