class LoggerWriter:

    def __init__(self, level):
        self.level = level

def write(self, message):
    if message != '\n':
        self.level(message)

def flush(self):
    pass
how to redirect stdout and stderr to logger in py