-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert funcitonlogger to native null logger
- Loading branch information
JB Lovland
committed
Nov 17, 2023
1 parent
3613ee9
commit 00bc562
Showing
3 changed files
with
39 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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 |