Here are the examples of the python api sys._stdout taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
0
Source : fit_job_handler.py
with BSD 3-Clause "New" or "Revised" License
from notmatthancock
with BSD 3-Clause "New" or "Revised" License
from notmatthancock
def setup_logging(capture_std_out=True):
""" Sets up logging formatting, etc
Parameters
----------
capture_std_out : bool, default=True
If True, then std out gets captured and written to the log
file. This is useful for capture the printed output from
models for which you do not have control to redirect their
status outputs (e.g., the fitting status of a scikit-learn model)
"""
logger_filename = "fit-log.txt"
if os.path.exists(logger_filename):
os.remove(logger_filename)
line_fmt = ("[%(asctime)s] [%(name)s:%(lineno)d] "
"%(levelname)-8s %(message)s")
date_fmt = "%Y-%m-%d %H:%M:%S"
logging.basicConfig(
filename=logger_filename, format=line_fmt,
datefmt=date_fmt, level=logging.DEBUG)
if capture_std_out:
class StdOutLogger:
_logger = logging.getLogger('STD OUT CAPTURE')
def write(self, message):
if message != '\n':
self._logger.info(message)
def flush(self):
pass
sys._stdout = sys.stdout
sys.stdout = StdOutLogger()
class FitJobHandler: