Skip to content

Commit

Permalink
harmonise logging
Browse files Browse the repository at this point in the history
only one logger but different handlers
  • Loading branch information
djbrown committed Apr 23, 2023
1 parent b50dd73 commit 611323f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/base/management/commands/correct_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from games.models import Game, Team
from players.models import Player, Score

LOGGER = logging.getLogger('hbscorez.command')
LOGGER = logging.getLogger('hbscorez')


class Command(BaseCommand):
Expand Down
2 changes: 1 addition & 1 deletion src/games/management/commands/import_games.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def import_league(self, league: League):
try:
self.import_game(game_row, league)
except Exception:
logging.getLogger('mail').exception("Could not import Game")
LOGGER.exception("Could not import Game")

def import_game(self, game_row, league: League):

Expand Down
6 changes: 2 additions & 4 deletions src/hbscorez/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,18 @@
'formatter': 'simple',
},
'mail': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True,
# 'reporter_class': 'base.error_reporter.CustomErrorReporter', # new in django 3
},
},
'loggers': {
'hbscorez': {
'handlers': ['file', 'console'],
'handlers': ['file', 'console', 'mail'],
'level': 'DEBUG',
'propagate': True,
},
'mail': {
'handlers': ['mail'],
},
},
}

Expand Down
8 changes: 4 additions & 4 deletions src/leagues/management/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def scrape_associations(options):
try:
scrape_association(bhv_id, options)
except Exception:
logging.getLogger('mail').exception("Could not create Association")
LOGGER.exception("Could not create Association")


def scrape_association(bhv_id: int, options):
Expand Down Expand Up @@ -98,7 +98,7 @@ def scrape_districs(association: Association, options):
try:
scrape_district(item, association, options)
except Exception:
logging.getLogger('mail').exception("Could not create District")
LOGGER.exception("Could not create District")


def scrape_district(district_item, association: Association, options):
Expand All @@ -125,7 +125,7 @@ def scrape_district(district_item, association: Association, options):
try:
scrape_season(district, start_year, options)
except Exception:
logging.getLogger('mail').exception("Could not create Season")
LOGGER.exception("Could not create Season")


def scrape_season(district, start_year, options):
Expand Down Expand Up @@ -155,7 +155,7 @@ def scrape_season(district, start_year, options):
try:
scrape_league(league_link, district, season, options)
except Exception:
logging.getLogger('mail').exception("Could not create League")
LOGGER.exception("Could not create League")


@transaction.atomic
Expand Down
2 changes: 1 addition & 1 deletion src/leagues/tests/integration/test_setup_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_no_youth(self):


class LongLeagueNames(IntegrationTestCase):
def test_youth(self):
def test_long(self):
self.assert_command('setup', '-a', 83, '-d', 83, '-s', 2019, '-l', 45646, 45651, '--youth')

leagues = self.assert_objects(League, count=2).order_by('name')
Expand Down
2 changes: 1 addition & 1 deletion src/players/management/commands/import_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def import_league(self, league):
try:
self.import_game(game)
except Exception:
logging.getLogger('mail').exception("Could not import Report")
LOGGER.exception("Could not import Report")

def import_game(self, game: Game):
if self.options['games'] and game.number not in self.options['games']:
Expand Down

0 comments on commit 611323f

Please sign in to comment.