shamo.utils.logging.StreamToLogger

class shamo.utils.logging.StreamToLogger(logger, log_level=20, pattern='')[source]

Bases: object

Pipe a stream to a logger.

The implementation is based on the blog post available at: http://techies-world.com/how-to-redirect-stdout-and-stderr-to-a-logger-in-python/

Parameters
loggerlogging.Logger

The logger to pipe the stream to.

log_levelint

The logging level of the piped messages.

patternstr

A pattern containing a ‘level’ and a ‘text’ group.

Methods

flush

A dummy flush function.

write

Write a message to the logger.

Attributes

pattern

flush()[source]

A dummy flush function.

write(buf)[source]

Write a message to the logger.

Parameters
bufbytes

The buffer to read from.