/dev/null as a file-like object, or logging to nothing

Torsten Bronger bronger at physik.rwth-aachen.de
Sat Sep 8 18:52:57 CEST 2007


Is there a portable and simply way to direct file-like IO to simply
nothing?  I try to implement some sort of NullLogging by saying

--8<---------------cut here---------------start------------->8---
import logging
if options.logging:
    logging.basicConfig(level=logging.DEBUG, filename=options.logfile, filemode="w",
                        format='%(asctime)s %(name)s %(levelname)s   %(message)s')
    # redirect logging to a memory buffer in order to simply ignore it.
    import StringIO
--8<---------------cut here---------------end--------------->8---

However, this consumes memory.  Is there a better way?


Torsten Bronger, aquisgrana, europa vetus
                                      Jabber ID: bronger at jabber.org
                      (See http://ime.webhop.org for ICQ, MSN, etc.)

More information about the Python-list mailing list