Skip to content

Commit

Permalink
Fix logging use to be more consistent
Browse files Browse the repository at this point in the history
This makes logging use more consistent across the files. Now all
module-level loggers are named LOGGER rather than a mix of LOGGER and
logger.

This removes the import and logger creation in files that don't use the
logger at all, too.
  • Loading branch information
willkg committed May 23, 2024
1 parent 7605048 commit 3a8595a
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 76 deletions.
14 changes: 7 additions & 7 deletions antenna/breakpad_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
)


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


#: Bad fields we should never save, so remove them from the payload before
Expand Down Expand Up @@ -234,13 +234,13 @@ def extract_payload(self, req):
# If there was a problem extracting the value as text, then log
# it and add a note
msg = f"extract payload text part exception: {mpe.description}"
logger.error(msg)
LOGGER.error(msg)
crash_report.notes.append(msg)

else:
if part.content_type != "application/octet-stream":
msg = f"unknown content type: {part.name} {part.content_type}"
logging.info(msg)
LOGGER.info(msg)
crash_report.notes.append(msg)

# This is a dump, so add it to dumps using a sanitized dump name.
Expand All @@ -253,7 +253,7 @@ def extract_payload(self, req):
# 1. boundaries are missing or malformed
# 2. missing EOL sequences
# 3. file parts are missing Content-Type declaration
logger.error(f"extract payload exception: {mpe.description}")
LOGGER.error(f"extract payload exception: {mpe.description}")
raise MalformedCrashReport("invalid_payload_structure") from mpe

if not crash_report.annotations:
Expand All @@ -263,7 +263,7 @@ def extract_payload(self, req):
# If the crash payload has both kvpairs and a JSON blob, then it's malformed
# so we add a note and log it.
msg = "includes annotations in both json-encoded extra and formdata parts"
logger.info(msg)
LOGGER.info(msg)
crash_report.notes.append(msg)

# Add a note about how the annotations were encoded in the crash report. For
Expand Down Expand Up @@ -365,7 +365,7 @@ def on_post(self, req, resp):
# one.
if "uuid" in raw_crash and validate_crash_id(raw_crash["uuid"]):
crash_id = raw_crash["uuid"]
logger.info("%s has existing crash_id", crash_id)
LOGGER.info("%s has existing crash_id", crash_id)

else:
crash_id = create_crash_id(
Expand All @@ -374,7 +374,7 @@ def on_post(self, req, resp):
raw_crash["uuid"] = crash_id

# Log throttle result and add to raw crash
logger.info(
LOGGER.info(
"%s: matched by %s; returned %s",
crash_id,
rule_name,
Expand Down
4 changes: 2 additions & 2 deletions antenna/ext/crashpublish_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging


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


class CrashPublishBase:
Expand Down Expand Up @@ -47,7 +47,7 @@ def __init__(self, config):
def publish_crash(self, crash_report):
"""Publish the crash id."""
crash_id = crash_report.crash_id
logger.info("crash publish no-op: %s", crash_id)
LOGGER.info("crash publish no-op: %s", crash_id)
self.published_things.append({"crash_id": crash_id})

# Nix all but the last 10 crashes
Expand Down
4 changes: 2 additions & 2 deletions antenna/ext/crashstorage_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging


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


class CrashIDNotFound(Exception):
Expand Down Expand Up @@ -57,7 +57,7 @@ def __init__(self, config):

def save_crash(self, crash_report):
crash_id = crash_report.crash_id
logger.info("crash storage no-op: %s", crash_id)
LOGGER.info("crash storage no-op: %s", crash_id)
self.saved_things.append(crash_report)

# Nix all but the last 10 crashes
Expand Down
6 changes: 3 additions & 3 deletions antenna/ext/fs/crashstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from antenna.util import get_date_from_crash_id, json_ordered_dumps


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


class FSCrashStorage(CrashStorageBase):
Expand Down Expand Up @@ -87,7 +87,7 @@ def _get_dump_name_path(self, crash_id, dump_name):
)

def _save_file(self, fn, contents):
logger.debug("Saving file %r", fn)
LOGGER.debug("Saving file %r", fn)
path = os.path.dirname(fn)

# FIXME(willkg): What happens if there is something here already and
Expand All @@ -96,7 +96,7 @@ def _save_file(self, fn, contents):
try:
os.makedirs(path)
except OSError:
logger.exception("Threw exception while trying to make path %r", path)
LOGGER.exception("Threw exception while trying to make path %r", path)
# FIXME(willkg): If we ever make this production-ready, we
# need a better option here.
return
Expand Down
5 changes: 3 additions & 2 deletions antenna/ext/gcs/crashstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from antenna.ext.crashstorage_base import CrashStorageBase, CrashIDNotFound
from antenna.util import get_date_from_crash_id, json_ordered_dumps

logger = logging.getLogger(__name__)

LOGGER = logging.getLogger(__name__)


def generate_test_filepath():
Expand Down Expand Up @@ -83,7 +84,7 @@ def __init__(self, config):
self.bucket = self.config("bucket_name")

if emulator := os.environ.get("STORAGE_EMULATOR_HOST"):
logger.debug(
LOGGER.debug(
"STORAGE_EMULATOR_HOST detected, connecting to emulator: %s",
emulator,
)
Expand Down
4 changes: 2 additions & 2 deletions antenna/ext/pubsub/crashpublish.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from antenna.app import register_for_verification


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


class PubSubCrashPublish(CrashPublishBase):
Expand Down Expand Up @@ -86,7 +86,7 @@ def __init__(self, config):
self.topic_name = self.config("topic_name")

if emulator := os.environ.get("PUBSUB_EMULATOR_HOST"):
logger.debug(
LOGGER.debug(
"PUBSUB_EMULATOR_HOST detected, connecting to emulator: %s",
emulator,
)
Expand Down
8 changes: 4 additions & 4 deletions antenna/ext/s3/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from antenna.util import retry


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


class KeyNotFound(Exception):
Expand Down Expand Up @@ -143,7 +143,7 @@ def __init__(self, config):
ValueError,
],
wait_time_generator=wait_times_connect,
module_logger=logger,
module_logger=LOGGER,
)
def _build_client(self):
# Either they provided ACCESS_KEY and SECRET_ACCESS_KEY in which case
Expand Down Expand Up @@ -195,7 +195,7 @@ def check_health(self, state):
ClientError
],
wait_time_generator=wait_times_save,
module_logger=logger,
module_logger=LOGGER,
)
def save_file(self, path, data):
"""Save a single file to S3.
Expand Down Expand Up @@ -226,7 +226,7 @@ def save_file(self, path, data):
ClientError
],
wait_time_generator=wait_times_save,
module_logger=logger,
module_logger=LOGGER,
)
def load_file(self, path):
"""Load a file from S3.
Expand Down
4 changes: 0 additions & 4 deletions antenna/ext/s3/crashstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

import json
import logging

from everett.manager import Option, parse_class

Expand All @@ -13,9 +12,6 @@
from antenna.util import get_date_from_crash_id, json_ordered_dumps


logger = logging.getLogger(__name__)


class S3CrashStorage(CrashStorageBase):
"""Save raw crash files to S3.
Expand Down
4 changes: 2 additions & 2 deletions antenna/ext/sqs/crashpublish.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from antenna.util import retry


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


def wait_times_connect():
Expand Down Expand Up @@ -124,7 +124,7 @@ def __init__(self, config):
ValueError,
],
wait_time_generator=wait_times_connect,
module_logger=logger,
module_logger=LOGGER,
)
def _build_client(self):
# Either they provided ACCESS_KEY and SECRET_ACCESS_KEY in which case
Expand Down
4 changes: 0 additions & 4 deletions antenna/health_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from collections import OrderedDict
import json
import logging
import os

import falcon
Expand All @@ -13,9 +12,6 @@
from antenna.libmarkus import METRICS


logger = logging.getLogger(__name__)


class BrokenResource:
"""Handle ``/__broken__`` endpoint."""

Expand Down
10 changes: 5 additions & 5 deletions antenna/throttler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from everett.manager import Option


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


ACCEPT = 0 # save and process
Expand Down Expand Up @@ -250,7 +250,7 @@ def match_b2g(throttler, data):
and safe_get(data, "ProductName").lower() == "b2g"
)
if is_b2g:
logger.info("ProductName B2G: fake accept")
LOGGER.info("ProductName B2G: fake accept")
return True
return False

Expand All @@ -262,7 +262,7 @@ def match_unsupported_product(throttler, data):
is_not_supported = products and product_name not in products

if is_not_supported:
logger.info("ProductName rejected: %r", product_name)
LOGGER.info("ProductName rejected: %r", product_name)
return True
return False

Expand All @@ -280,11 +280,11 @@ def match_unsupported_android_packagename(throttler, data):
# NOTE(willkg): safe_get converts None to "None", so we need to test for that
# here
if packagename == "None":
logger.info(
LOGGER.info(
"Android_PackageName rejected: %s no Android_PackageName", product_name
)
else:
logger.info(
LOGGER.info(
"Android_PackageName rejected: %s %r", product_name, packagename
)
return True
Expand Down
6 changes: 3 additions & 3 deletions antenna/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from more_itertools import peekable


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


UTC = isodate.UTC
Expand Down Expand Up @@ -227,12 +227,12 @@ def some_thing_that_fails():
Example with arguments::
import logging
logger = logging.getLogger(__name__)
LOGGER = logging.getLogger(__name__)
@retry(
retryable_exceptions=[SocketTimeout, ConnectionError],
retryable_return=lambda resp: resp.status_code != 200,
module_logger=logger
module_logger=LOGGER
)
def some_thing_that_does_connections():
pass
Expand Down
5 changes: 0 additions & 5 deletions systemtest/test_25mblimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

import logging

import pytest
import requests

from testlib import mini_poster


logger = logging.getLogger(__name__)


class Test25mbLimit:
"""Post a crash that's too big--it should be rejected"""

Expand Down
4 changes: 0 additions & 4 deletions systemtest/test_content_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@

from http.client import HTTPConnection, HTTPSConnection, RemoteDisconnected
from contextlib import contextmanager
import logging
import urllib

import pytest

from testlib import mini_poster


logger = logging.getLogger(__name__)


@contextmanager
def http_post(posturl, headers, data):
parsed = urllib.parse.urlparse(posturl)
Expand Down
4 changes: 0 additions & 4 deletions systemtest/test_discards.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

import logging
import requests

from testlib import mini_poster


logger = logging.getLogger(__name__)


class TestDiscarded:
def test_wrong_boundary(self, posturl, crash_generator):
"""Post a crash with a header with wrong boundary marker."""
Expand Down
5 changes: 0 additions & 5 deletions systemtest/test_dockerflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

import logging

import requests


LOGGER = logging.getLogger(__name__)


class TestDockerflow:
def test_version(self, baseurl):
resp = requests.get(baseurl + "__version__", timeout=5)
Expand Down
Loading

0 comments on commit 3a8595a

Please sign in to comment.