668 charge.failure_message, charge.failure_code
669 ),
670 )
671 logging.info(f"Successful charge: {charge.id}. Order ID: {order_identifier}")672
673 return redirect(make_frontend_url(f'orders/{order_identifier}/view'))
674
650 try:
651 charge = OmisePaymentsManager.charge_payment(order_identifier, token)
652 except omise.errors.BaseError as e:
653 logging.exception(654 f"""OmiseError: {repr(e)}. See https://www.omise.co/api-errors"""
655 )
656 return jsonify(status=False, error=f"Omise Failure Message: {str(e)}")
311 speaker.thumbnail_image_url = uploaded_images['thumbnail_image_url']
312 speaker.icon_image_url = uploaded_images['icon_image_url']
313 save_to_db(speaker)
314 logging.info(315 f'Resized images saved successfully for speaker with id: {speaker_id}'
316 )
317 except (requests.exceptions.HTTPError, requests.exceptions.InvalidURL):
286 sponsors = Sponsor.query.filter_by(event_id=event_id, deleted_at=None).all()
287 for sponsor in sponsors:
288 try:
289 logging.info(f'Sponsor logo url generation task started {sponsor.logo_url}')290 new_logo_url = create_save_resized_image(
291 image_file=sponsor.logo_url, resize=False
292 )
272 user.thumbnail_image_url = uploaded_images['thumbnail_image_url']
273 user.icon_image_url = uploaded_images['icon_image_url']
274 save_to_db(user)
275 logging.info(f'Resized images saved successfully for user with id: {user_id}')276 except (requests.exceptions.HTTPError, requests.exceptions.InvalidURL):
277 logging.exception(
278 'Error encountered while generating resized images for user with id: {}'.format(
Formatting the message manually before passing it to a logging
call does unnecessary work if logging is disabled. Consider using the logging
module's built-in formatting features to avoid that.
If your logging level is set to "WARNING"
, but the logging call is:
logging.debug("Data: %s", data)
In the above example, there will be no logging as the level debug
is below warning
. The conversion of the data
object to a string will be skipped by the logging module resulting in improved performance.
logging.debug(f"Data: {data}")
In the code shown above, the conversion of the data
object to a string will happen regardless of whether the message is logged or not (which is based on the log level).
import logging
import inspect
logging.basicConfig(level=logging.INFO)
logging.debug(f"Entered function {inspect.stack[0][3]}"))
import logging
import inspect
logging.basicConfig(level=logging.INFO)
logging.debug("Entered function %s", inspect.stack[0][3])