On 29/12/2013 at 07:42, xxxxxxxx wrote:
You could overwrite sys.stdout with your own file-like object that redirects the write() calls to the original
stdout and your own file. You should prefer to use your own printing mechanism however to not break
other plugins or scripts in case your implementation is buggy.
> import logging
>
> import cStringIO as cstio
>
>
>
>
> logfile = cstio.StringIO()
>
> logger = logging.Logger("conner's logger")
>
> logger.addHandler(logging.StreamHandler(logfile))
>
> logger.addHandler(logging.StreamHandler(sys.stdout))
>
>
>
>
> def get_log(self) :
>
> logfile.seek(0)
>
> data = logfile.read()
>
> logfile.seek(0, 2)
>
> return data
Simply put everything into the logger instead of using the print keyword.
Best,
-Niklas