def test_log_level_warning(self, caplog): """Make sure we are not outputting the exec time on level > INFO """ caplog.set_level(logging.WARNING) my_message = 'my-message' with log_exec_time(my_message): some_func() assert not caplog.records
def test_with_param_logger(self, caplog): """Test when we provide a logger This is just a parameter check at this point. We're not checking that we have multiple logging buffers """ caplog.set_level(logging.INFO) my_message = 'my-message' with log_exec_time(my_message, logger): some_func() last_log = caplog.records[-1] assert last_log.message.startswith(my_message)
def populate_monthly_metrics_for_site(site_id): try: site = Site.objects.get(id=site_id) msg = 'Ran populate_monthly_metrics_for_site. [{}]:{}' with log_exec_time(msg.format(site.id, site.domain)): fill_last_smm_month(site=site) except Site.DoesNotExist: msg = '{prefix}:SITE:ERROR: site_id:{site_id} Site does not exist' logger.error(msg.format(prefix=FPM_LOG_PREFIX, site_id=site_id)) except Exception: # pylint: disable=broad-except msg = '{prefix}:SITE:ERROR: site_id:{site_id} Other error' logger.exception(msg.format(prefix=FPM_LOG_PREFIX, site_id=site_id))
def test_with_default_logger(self, caplog): """Our basic `log_exec_time` test """ caplog.set_level(logging.INFO) my_message = 'my-message' with log_exec_time(my_message): some_func() last_log = caplog.records[-1] # Very basic check. We can improve on it by monkeypatching timit or just # checking the number and 's' for seconds at the end of the string # For now, we just want to check that our message gets into the log assert last_log.message.startswith(my_message)
def populate_monthly_metrics_for_site(site_id): site = Site.objects.get(id=site_id) msg = 'Ran populate_monthly_metrics_for_site. [{}]:{}' with log_exec_time(msg.format(site.id, site.domain)): fill_last_smm_month(site=site)