Added logging config.
This commit is contained in:
parent
812bb66219
commit
a9242b2f3a
1 changed files with 31 additions and 0 deletions
31
core/my_logger.py
Normal file
31
core/my_logger.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import logging
|
||||
import sys
|
||||
|
||||
|
||||
class StreamToLogger(object):
|
||||
"""
|
||||
Fake file-like stream object that redirects writes to a logger instance.
|
||||
"""
|
||||
|
||||
def __init__(self, logger, log_level=logging.INFO):
|
||||
self.logger = logger
|
||||
self.log_level = log_level
|
||||
self.linebuf = ""
|
||||
|
||||
def write(self, buf):
|
||||
for line in buf.rstrip().splitlines():
|
||||
self.logger.log(self.log_level, line.rstrip())
|
||||
|
||||
|
||||
logging.basicConfig(
|
||||
filename="log.log",
|
||||
format="%(asctime)s:%(levelname)s:%(name)s:%(message)s",
|
||||
filemode="a+",
|
||||
level=logging.DEBUG,
|
||||
)
|
||||
stdout_logger = logging.getLogger("STDOUT")
|
||||
sl = StreamToLogger(stdout_logger, logging.INFO)
|
||||
sys.stdout = sl
|
||||
stderr_logger = logging.getLogger("STDERR")
|
||||
sl = StreamToLogger(stderr_logger, logging.ERROR)
|
||||
sys.stderr = sl
|
||||
Loading…
Add table
Add a link
Reference in a new issue