GrampsLocale: Suppress double printing of log messages
Grampsapp.py sets a global handler, so install one only during the first init and remove it when done. svn: r21644
This commit is contained in:
parent
80ac126dfa
commit
66ded552dd
@ -32,10 +32,8 @@ import os
|
|||||||
import locale
|
import locale
|
||||||
import logging
|
import logging
|
||||||
LOG = logging.getLogger("grampslocale")
|
LOG = logging.getLogger("grampslocale")
|
||||||
_hdlr = logging.StreamHandler()
|
|
||||||
_hdlr.setFormatter(logging.Formatter(fmt="%(name)s.%(levelname)s: %(message)s"))
|
|
||||||
LOG.addHandler(_hdlr)
|
|
||||||
HAVE_ICU = False
|
HAVE_ICU = False
|
||||||
|
_hdlr = None
|
||||||
try:
|
try:
|
||||||
from icu import Locale, Collator
|
from icu import Locale, Collator
|
||||||
HAVE_ICU = True
|
HAVE_ICU = True
|
||||||
@ -160,6 +158,10 @@ class GrampsLocale(object):
|
|||||||
|
|
||||||
def __init_first_instance(self, localedir, lang=None,
|
def __init_first_instance(self, localedir, lang=None,
|
||||||
domain=None, language=None):
|
domain=None, language=None):
|
||||||
|
global _hdlr
|
||||||
|
_hdlr = logging.StreamHandler()
|
||||||
|
_hdlr.setFormatter(logging.Formatter(fmt="%(name)s.%(levelname)s: %(message)s"))
|
||||||
|
LOG.addHandler(_hdlr)
|
||||||
|
|
||||||
#First, globally set the locale to what's in the environment:
|
#First, globally set the locale to what's in the environment:
|
||||||
try:
|
try:
|
||||||
@ -238,13 +240,13 @@ class GrampsLocale(object):
|
|||||||
|
|
||||||
self.initialized = True
|
self.initialized = True
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, localedir=None, lang=None, domain=None, languages=None):
|
def __init__(self, localedir=None, lang=None, domain=None, languages=None):
|
||||||
"""
|
"""
|
||||||
Init a GrampsLocale. Run __init_first_instance() to set up the
|
Init a GrampsLocale. Run __init_first_instance() to set up the
|
||||||
environement if this is the first run. Return __first_instance
|
environement if this is the first run. Return __first_instance
|
||||||
otherwise if called without arguments.
|
otherwise if called without arguments.
|
||||||
"""
|
"""
|
||||||
|
global _hdlr
|
||||||
if self == self._GrampsLocale__first_instance:
|
if self == self._GrampsLocale__first_instance:
|
||||||
if not self.initialized:
|
if not self.initialized:
|
||||||
self._GrampsLocale__init_first_instance(localedir, lang,
|
self._GrampsLocale__init_first_instance(localedir, lang,
|
||||||
@ -293,9 +295,8 @@ class GrampsLocale(object):
|
|||||||
self.translation = self._get_translation(self.localedomain,
|
self.translation = self._get_translation(self.localedomain,
|
||||||
self.localedir, self.language)
|
self.localedir, self.language)
|
||||||
self._set_dictionaries()
|
self._set_dictionaries()
|
||||||
|
if _hdlr:
|
||||||
|
LOG.removeHandler(_hdlr)
|
||||||
|
|
||||||
|
|
||||||
def _get_translation(self, domain = None,
|
def _get_translation(self, domain = None,
|
||||||
localedir = None,
|
localedir = None,
|
||||||
|
Loading…
Reference in New Issue
Block a user