Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[python] Add
verbose
deprecation notice and util.py
- Add a deprecation notice for the optional `verbose` argument - Create `tools/util.py` to contain technical helpers such as the deprecation warning used in various submodules.
- Loading branch information
Showing
10 changed files
with
72 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,32 +8,6 @@ | |
# import these submodules by default | ||
from . import mix_adapt, density, sampler, tools | ||
|
||
_log_to_stdout = False | ||
def log_to_stdout(verbose=False): | ||
''' | ||
Turn on logging and add a handler which prints to stderr, if not active | ||
yet. | ||
:param verbose: | ||
Bool; if ``True``, output non-critical status information | ||
''' | ||
global _log_to_stdout | ||
import logging | ||
import sys | ||
logger = logging.getLogger(__name__) | ||
|
||
if verbose: | ||
logger.setLevel(logging.INFO) | ||
else: | ||
logger.setLevel(logging.WARNING) | ||
|
||
if not _log_to_stdout: | ||
formatter = logging.Formatter('[%(levelname)s] %(message)s') | ||
handler = logging.StreamHandler(sys.stdout) | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
_log_to_stdout = True | ||
|
||
log_to_stdout() | ||
# Log to stdout per default. The log handler can be removed to use pypmc | ||
# as a library. | ||
tools.util.log_to_stdout() | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pluegh
Author
Contributor
|
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
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
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,38 @@ | ||
import logging | ||
|
||
_log_to_stdout = False | ||
def log_to_stdout(verbose=False): | ||
''' | ||
Turn on logging and add a handler which prints to stderr, if not active | ||
yet. | ||
:param verbose: | ||
Bool; if ``True``, output non-critical status information | ||
''' | ||
global _log_to_stdout | ||
import logging | ||
import sys | ||
logger = logging.getLogger(__name__) | ||
|
||
if verbose: | ||
logger.setLevel(logging.INFO) | ||
else: | ||
logger.setLevel(logging.WARNING) | ||
|
||
if not _log_to_stdout: | ||
formatter = logging.Formatter('[%(levelname)s] %(message)s') | ||
handler = logging.StreamHandler(sys.stdout) | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
_log_to_stdout = True | ||
|
||
def depr_warn_verbose(logger_name): | ||
logger = logging.getLogger(logger_name) | ||
logger.warn( | ||
f"The optional argument 'verbose' is deprecated and " | ||
f"will be removed in the future. Instead, use the log " | ||
f"level of logging.getLogger({logger_name}) or a parent." | ||
) | ||
|
@pluegh Why did you not call this
tools.output
?