logging - Log to file and console python -


i'm using python's logging module log debug strings file give me log use script attached don't give me output screen how can show print in screen , print log formatt ? help?

class streamtologger(object):    """    fake file-like stream object redirects writes logger instance.    """    def __init__(self, logger, log_level=logging.info):       self.logger = logger       self.log_level = log_level       self.linebuf = ''     def write(self, buf):       line in buf.rstrip().splitlines():          self.logger.log(self.log_level, line.rstrip())  logging.basicconfig(    level=logging.debug,    format='%(asctime)s:%(levelname)s:%(name)s:%(message)s',    filename="out.log",    filemode='a' )  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 


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -