FTP (ftplib) output capture

C

ChaosKCW

Hi

Has anyone caputerd the output from the std ftp lib? It seems a bit
annoying that everything is printed to stdout. It means incorporating
this into any real program is a problem. It would have been much better
if they used the std logging module and hooked up a console logger for
the feault ftp application. Alas it isnt that way.

Capturing stdout like this??? :

import sys

sys.stdout = open('bb', 'w)

But I want to re-route it to the logging module not a file , so do I
need to write a steam object?

Thanks,
 
S

Simon Forman

ChaosKCW said:
Hi

Has anyone caputerd the output from the std ftp lib? It seems a bit
annoying that everything is printed to stdout. It means incorporating
this into any real program is a problem. It would have been much better
if they used the std logging module and hooked up a console logger for
the feault ftp application. Alas it isnt that way.

Capturing stdout like this??? :

import sys

sys.stdout = open('bb', 'w)

But I want to re-route it to the logging module not a file , so do I
need to write a steam object?

Thanks,

ftplib pre-dates the standard logging system by a bit.

I think ftplib only prints stuff if you set its (the FTP class
instances') debug level to greater than 0.

If you really want to replace sys.stdout with something that passes the
data to a logger, then something like the following (untested) class
should do it:

class FileLog:
def __init__(self, log):
self.log = log
def write(self, data):
self.log.debug(data)

The best solution might be to subclass or rewrite FTP to really do what
you want. I believe one of the goals of Python-3000 is better
integration of the standard library with the new-ish standard logging
system, so if you do a good job send it in. ;-)

Peace,
~Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top