Search code examples
pythonloggingtwisted

Is it possible to disable logging entirely in Python Twisted?


I notice that the generally accepted solution is to send it to /dev/null. However, by design, the log file gets rotated whenever a SIGUSR1 gets sent to twisted. This will then rotate /dev/null, which is undesired. In fact, I have half a mind to think that this is a bug.

Anyway, does anyone know how to circumvent this?


Solution

  • You can write a custom logger that doesn't actually log anything:

    # yourlogger.py
    from zope.interface import implementer
    from twisted.logger import ILogObserver
    
    @implementer(ILogObserver)
    class NullObserver(object):
        def __call__(self, event):
            pass
    

    Make sure it is importable and then ask for it from the command line:

    $ twistd --logger yourlogger.NullObserver -y ...