I would like to build an adaptor object which behaves like a (text) file (opened for output) and forwards each complete line given to it to standard Python logging. Which logger to use and which level to be assigned to lines logged should be specified in the ctor.
Suggestions? Code? Caveats?
I’ve already done this, see my post about it.
Update: It could be a subclass of
file, but it doesn’t especially support other file operations, so there’s no particular need for it to be afilesubclass.Further update: It’s up to the OP to adapt the approach in my post – you can subclass
fileif you like, handle buffering, etc. – whatever you need, it doesn’t seem like a lot of work either way.