Project

General

Profile

Actions

Feature #9534

open

logging of stdout and stderr

Added by Le Jeune Maude almost 9 years ago.

Status:
New
Priority:
Normal
Assigned To:
-
Category:
-
Start date:
03/25/2015
Due date:
% Done:

0%

Estimated time:

Description

cf http://www.electricmonk.nl/log/2011/08/14/redirect-stdout-and-stderr-to-a-logger-in-python/

Il suffit d'ajouter

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())

sl = StreamToLogger(logger, logging.INFO)
sys.stdout = sl
sys.stderr = sl

No data to display

Actions

Also available in: Atom PDF