[Chicago] How do you troubleshoot cgi errors?

David Rock david at graniteweb.com
Mon Jul 23 19:19:43 CEST 2007


* Ian Bicking <ianb at colorstudy.com> [2007-07-23 09:29]:
> 
> You can do something like this:
> 
> class ReplStdOut(object):
>      def __init__(self, *files):
>          self.files = files
>      def __getattr__(self, attr):
>          def repl_method(*args, **kw):
>              for f in self.files:
>                  value = getattr(f, attr)(*args, **kw)
>              return value
>          return repl_method
> 
> sys.stdout = ReplStdout(sys.stdout, open('output.log', 'a'))

For those that want to try this out, there is a small typo, but it does
work (very well, btw).  Here is the fixed version:

class ReplStdOut(object):
     def __init__(self, *files):
         self.files = files
     def __getattr__(self, attr):
         def repl_method(*args, **kw):
             for f in self.files:
                 value = getattr(f, attr)(*args, **kw)
             return value
         return repl_method

sys.stdout = ReplStdOut(sys.stdout, open('output.log', 'a'))


Ok, this is the kind of stuff that reminds me there is always something
new to learn :-)

It looks like this does what I need it to, but what is it actually
doing?  Best as I can tell, this is basically creating a "tee" for
stdout, and looks like it could be to multiple files, not just stdout
and a file, right?  The question I have now is _why_ does this work?

Thanks for the help, btw.  Now all I have to do is wait for my stuff to
break again ;-)

-- 
David Rock
david at graniteweb.com


More information about the Chicago mailing list