Skip to content

logging: Add handler param to basicConfig. #1023

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy