From 95e69b5ed29e4acb3b46fe737247d35d0f22aa9b Mon Sep 17 00:00:00 2001 From: ctrl-alt-soneca Date: Tue, 26 Jul 2022 10:57:50 +0100 Subject: [PATCH] models: logging strings unicode-friendly --- invenio_pidstore/models.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/invenio_pidstore/models.py b/invenio_pidstore/models.py index b6703be..e475918 100644 --- a/invenio_pidstore/models.py +++ b/invenio_pidstore/models.py @@ -147,11 +147,11 @@ def create(cls, pid_type, pid_value, pid_provider=None, if object_type and object_uuid: obj.assign(object_type, object_uuid) db.session.add(obj) - logger.info("Created PID {0}:{1}".format(pid_type, pid_value), + logger.info(u"Created PID {0}:{1}".format(pid_type, pid_value), extra={'pid': obj}) except IntegrityError: logger.exception( - "PID already exists: {0}:{1}".format(pid_type, pid_value), + u"PID already exists: {0}:{1}".format(pid_type, pid_value), extra=dict( pid_type=pid_type, pid_value=pid_value, @@ -163,7 +163,7 @@ def create(cls, pid_type, pid_value, pid_provider=None, raise PIDAlreadyExists(pid_type=pid_type, pid_value=pid_value) except SQLAlchemyError: logger.exception( - "Failed to create PID: {0}:{1}".format(pid_type, pid_value), + u"Failed to create PID: {0}:{1}".format(pid_type, pid_value), extra=dict( pid_type=pid_type, pid_value=pid_value, @@ -281,10 +281,10 @@ def assign(self, object_type, object_uuid, overwrite=False): self.object_uuid = object_uuid db.session.add(self) except SQLAlchemyError: - logger.exception("Failed to assign {0}:{1}".format( + logger.exception(u"Failed to assign {0}:{1}".format( object_type, object_uuid), extra=dict(pid=self)) raise - logger.info("Assigned object {0}:{1}".format( + logger.info(u"Assigned object {0}:{1}".format( object_type, object_uuid), extra=dict(pid=self)) return True @@ -311,10 +311,10 @@ def unassign(self): self.object_uuid = None db.session.add(self) except SQLAlchemyError: - logger.exception("Failed to unassign object.".format(self), + logger.exception(u"Failed to unassign object.".format(self), extra=dict(pid=self)) raise - logger.info("Unassigned object from {0}.".format(self), + logger.info(u"Unassigned object from {0}.".format(self), extra=dict(pid=self)) return True @@ -360,10 +360,10 @@ def redirect(self, pid): except IntegrityError: raise PIDDoesNotExistError(pid.pid_type, pid.pid_value) except SQLAlchemyError: - logger.exception("Failed to redirect to {0}".format( + logger.exception(u"Failed to redirect to {0}".format( pid), extra=dict(pid=self)) raise - logger.info("Redirected PID to {0}".format(pid), extra=dict(pid=self)) + logger.info(u"Redirected PID to {0}".format(pid), extra=dict(pid=self)) return True def reserve(self): @@ -460,10 +460,10 @@ def sync_status(self, status): self.status = status db.session.add(self) except SQLAlchemyError: - logger.exception("Failed to sync status {0}.".format(status), + logger.exception(u"Failed to sync status {0}.".format(status), extra=dict(pid=self)) raise - logger.info("Synced PID status to {0}.".format(status), + logger.info(u"Synced PID status to {0}.".format(status), extra=dict(pid=self)) return True