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

Fix duplicate logs in run_simulation #3354

Merged
merged 17 commits into from
Apr 30, 2024
Merged
Changes from 1 commit
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
12 changes: 11 additions & 1 deletion src/py/flwr/common/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# ==============================================================================
"""Flower Logger."""


import asyncio
import logging
from logging import WARN, LogRecord
from logging.handlers import HTTPHandler
Expand All @@ -24,6 +24,16 @@
LOGGER_NAME = "flwr"
FLOWER_LOGGER = logging.getLogger(LOGGER_NAME)
FLOWER_LOGGER.setLevel(logging.DEBUG)
# Detect if there is an Asyncio event loop already running.
# If yes, set logger.propagate to False so that only the child logger
# displays a message and the parent logger does not duplicate the message.
chongshenng marked this conversation as resolved.
Show resolved Hide resolved
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = None
finally:
if loop and loop.is_running():
FLOWER_LOGGER.propagate = False

LOG_COLORS = {
"DEBUG": "\033[94m", # Blue
Expand Down
Loading