-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: replace verbosity with standard logging patterns
Using verbosity and setLevel within the library is an antipattern. The approach shall be that the end client script sets the logging level, format, etc. instead.
- Loading branch information
1 parent
c1f8ae6
commit 382393b
Showing
16 changed files
with
107 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
|
||
def null_logger(name: str) -> logging.Logger: | ||
""" | ||
Create and return a logger with a NullHandler. | ||
This function creates a logger for the specified name and attaches a | ||
NullHandler to it. The NullHandler prevents logging messages from being | ||
automatically output to the console or other default handlers. This is | ||
particularly useful in library modules where you want to provide the | ||
users of the library the flexibility to configure their own logging behavior. | ||
Args: | ||
name (str): The name of the logger to be created. This is typically | ||
the name of the module in which the logger is | ||
created (e.g., using __name__). | ||
Returns: | ||
logging.Logger: A logger object configured with a NullHandler. | ||
Example: | ||
# In a library module | ||
logger = null_logger(__name__) | ||
logger.info("This info won't be logged to the console by default.") | ||
""" | ||
|
||
logger = logging.getLogger(name) | ||
logger.addHandler(logging.NullHandler()) | ||
return logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.