Skip to content

Commit

Permalink
Make sure loggers in all modules get configuration
Browse files Browse the repository at this point in the history
calling getLogger before a dict config gets set will create
an unconfigured logger, and this logger will be returned for
every further getLogger call. Also, getting the logger at
the start of the mainline of every module is convenient, but
excerberates this problem.

Change-Id: Ia5c295606737a165c3c90d44c6496d7ae3a1ec9f
  • Loading branch information
timo authored and awesome-michael committed May 6, 2021
1 parent 0c64fa6 commit fbb7e9c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
5 changes: 4 additions & 1 deletion sygnal/apnspushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from sygnal.notifications import ConcurrencyLimitedPushkin
from sygnal.utils import NotificationLoggerAdapter, twisted_sleep

logger = logging.getLogger(__name__)
logger = logging.getLogger(None)

SEND_TIME_HISTOGRAM = Histogram(
"sygnal_apns_request_time", "Time taken to send HTTP request to APNS"
Expand Down Expand Up @@ -94,6 +94,9 @@ class ApnsPushkin(ConcurrencyLimitedPushkin):
def __init__(self, name, sygnal, config):
super().__init__(name, sygnal, config)

global logger
logger = logging.getLogger(__name__)

nonunderstood = set(self.cfg.keys()).difference(self.UNDERSTOOD_CONFIG_FIELDS)
if len(nonunderstood) > 0:
logger.warning(
Expand Down
5 changes: 4 additions & 1 deletion sygnal/gcmpushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
labelnames=["pushkin", "code"],
)

logger = logging.getLogger(__name__)
logger = logging.getLogger(None)

GCM_URL = b"https://fcm.googleapis.com/fcm/send"
MAX_TRIES = 3
Expand Down Expand Up @@ -100,6 +100,9 @@ class GcmPushkin(ConcurrencyLimitedPushkin):
} | ConcurrencyLimitedPushkin.UNDERSTOOD_CONFIG_FIELDS

def __init__(self, name, sygnal, config, canonical_reg_id_store):
global logger
logger = logging.getLogger(__name__)

super(GcmPushkin, self).__init__(name, sygnal, config)

nonunderstood = set(self.cfg.keys()).difference(self.UNDERSTOOD_CONFIG_FIELDS)
Expand Down
7 changes: 5 additions & 2 deletions sygnal/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from .exceptions import InvalidNotificationException, NotificationDispatchException
from .notifications import Notification

logger = logging.getLogger(__name__)
logger = logging.getLogger(None)

NOTIFS_RECEIVED_COUNTER = Counter(
"sygnal_notifications_received", "Number of notification pokes received"
Expand Down Expand Up @@ -273,7 +273,7 @@ async def _handle_dispatch(self, root_span, request, log, notif, context):
except NotificationDispatchException:
request.setResponseCode(502)
log.warning("Failed to dispatch notification.", exc_info=True)
except Exception:
except Exception as e:
request.setResponseCode(500)
log.error("Exception whilst dispatching notification.", exc_info=True)
finally:
Expand Down Expand Up @@ -328,6 +328,9 @@ def __init__(self, sygnal):
Args:
sygnal (Sygnal): the Sygnal object
"""
global logger
logger = logging.getLogger(__name__)

root = Resource()
matrix = Resource()
push = Resource()
Expand Down
7 changes: 6 additions & 1 deletion sygnal/sygnal.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

from sygnal.http import PushGatewayApiServer

logger = logging.getLogger(__name__)
logger = logging.getLogger(None)

CONFIG_DEFAULTS: dict = {
"http": {"port": 5000, "bind_addresses": ["127.0.0.1"]},
Expand Down Expand Up @@ -65,6 +65,9 @@ def __init__(self, config, custom_reactor, tracer=opentracing.tracer):
custom_reactor: a Twisted Reactor to use.
tracer (optional): an OpenTracing tracer. The default is the no-op tracer.
"""

global logger

self.config = config
self.reactor = custom_reactor
self.pushkins = {}
Expand All @@ -73,6 +76,8 @@ def __init__(self, config, custom_reactor, tracer=opentracing.tracer):
logging_dict_config = config["log"]["setup"]
logging.config.dictConfig(logging_dict_config)

logger = logging.getLogger(__name__)

logger.debug("Started logging")

observer = twisted_log.PythonLoggingObserver()
Expand Down

0 comments on commit fbb7e9c

Please sign in to comment.