From e4202098b7c73fbef90f144c9a245c18ae4bc6e6 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Thu, 14 Mar 2013 23:07:47 +0000 Subject: [PATCH] [r21644]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: r21648 --- gramps/gen/utils/grampslocale.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gramps/gen/utils/grampslocale.py b/gramps/gen/utils/grampslocale.py index bbf55ef19..20feae699 100644 --- a/gramps/gen/utils/grampslocale.py +++ b/gramps/gen/utils/grampslocale.py @@ -32,10 +32,8 @@ import os import locale import logging LOG = logging.getLogger("grampslocale") -_hdlr = logging.StreamHandler() -_hdlr.setFormatter(logging.Formatter(fmt="%(name)s.%(levelname)s: %(message)s")) -LOG.addHandler(_hdlr) HAVE_ICU = False +_hdlr = None try: from icu import Locale, Collator HAVE_ICU = True @@ -160,6 +158,10 @@ class GrampsLocale(object): def __init_first_instance(self, localedir, lang=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: try: @@ -238,13 +240,13 @@ class GrampsLocale(object): self.initialized = True - def __init__(self, localedir=None, lang=None, domain=None, languages=None): """ Init a GrampsLocale. Run __init_first_instance() to set up the environement if this is the first run. Return __first_instance otherwise if called without arguments. """ + global _hdlr if self == self._GrampsLocale__first_instance: if not self.initialized: self._GrampsLocale__init_first_instance(localedir, lang, @@ -293,9 +295,8 @@ class GrampsLocale(object): self.translation = self._get_translation(self.localedomain, self.localedir, self.language) self._set_dictionaries() - - - + if _hdlr: + LOG.removeHandler(_hdlr) def _get_translation(self, domain = None, localedir = None,