Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamlined logger messages #119

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async def __connect(self):
while "database not connected":
if connection_attempt == 1:
self.__logger.info(
"Connecting to MongoDB (%s).",
"Worker (MongoD): Connecting to database (%s).",
self.hostname,
)
self.__client = motor.motor_asyncio.AsyncIOMotorClient(
Expand All @@ -99,14 +99,14 @@ async def __connect(self):
],
)
self.__logger.info(
"MongoDB (%s) connected.",
"Worker (MongoD): Successfully connected to database (%s).",
self.hostname,
)
except pymongo.errors.AutoReconnect as exc:
if connection_attempt == 1:
# Only log the error once
self.__logger.error(
"Cannot connect to config database at %s. Error: %s. Retrying in %f s.",
"Worker (MongoD): Cannot connect to config database at %s. Error: %s. Retrying in %f s.",
self.hostname,
exc,
timeout,
Expand Down Expand Up @@ -159,23 +159,23 @@ def _log_database_error(
database_name = str(database_model) if database_name is None else database_name

if error_code is None:
self.__logger.info("Database worker (%s): Database connected.", database_name)
self.__logger.info("Worker(%s database): Successfully connected.", database_name)
elif error_code == -2:
self.__logger.error("Database worker (%s): Failure in name resolution. Retrying.", database_name)
self.__logger.error("Worker(%s database): Failure in name resolution. Retrying.", database_name)
elif error_code == 104:
self.__logger.error("Database worker (%s): Database disconnected. Waiting to restart.", database_name)
self.__logger.error("Worker(%s database): Database disconnected. Waiting to restart.", database_name)
elif error_code == 111:
self.__logger.error("Database worker (%s): Connection refused. Waiting to start.", database_name)
self.__logger.error("Worker(%s database): Connection refused. Waiting to start.", database_name)
elif error_code == 211:
self.__logger.error("Database worker (%s): Initialising replica set. Waiting to start.", database_name)
self.__logger.error("Worker(%s database): Initialising replica set. Waiting to start.", database_name)
elif error_code == "resume_token":
self.__logger.error(
"Database worker (%s): Cannot resume Mongo DB change stream, there is no token. Starting from scratch.",
"Worker(%s database): Cannot resume Mongo DB change stream, there is no token. Starting from scratch.",
database_name,
)
else:
self.__logger.error(
"Database worker (%s): Connection error while monitoring database. Error: %s. Reconnecting in %.2f s.",
"Worker(%s database): Connection error while monitoring database. Error: %s. Reconnecting in %.2f s.",
database_name,
error_code,
timeout,
Expand Down
Loading