Skip to content
Open
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
24 changes: 15 additions & 9 deletions python-stdlib/logging/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def basicConfig(
format=None,
datefmt=None,
level=WARNING,
handlers=(),
stream=None,
encoding="UTF-8",
force=False,
Expand All @@ -235,19 +236,24 @@ def basicConfig(
if force or not logger.handlers:
for h in logger.handlers:
h.close()
logger.handlers = []
logger.handlers = list(handlers)

if filename is None:
handler = StreamHandler(stream)
else:
handler = FileHandler(filename, filemode, encoding)
if handlers is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right: handlers is never None unless explicitly passed in. Maybe you meant if not handlers?

if filename is None:
handler = StreamHandler(stream)
else:
handler = FileHandler(filename, filemode, encoding)
elif stream or filename:
raise ValueError("'stream' or 'filename' should not be "
"specified together with 'handlers'")

handler.setLevel(level)
handler.setFormatter(Formatter(format, datefmt))
for handler in logging.handlers:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logging is not defined in this scope.

handler.setLevel(level)
handler.setFormatter(Formatter(format, datefmt))

logger.setLevel(level)
logger.addHandler(handler)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the default handler (if none specified) is never added?

logger.addHandler(handler)

logger.setLevel(level)

if hasattr(sys, "atexit"):
sys.atexit(shutdown)
Loading