Найти - Пользователи
Полная версия: twistd + log
Начало » Python для новичков » twistd + log
1
apanyovin
Все доброго дня.

Подскажите плз в чем может быть проблем. Не выводит в лог сообщения из factory

class RedisMonitorFactory(redis.SubscriberFactory):
    maxDelay = 120
    continueTrying = True
    protocol = RedisMonitorProtocol
    task_queue = {}
    domain_settings = {}
    def __init__(self, conf):
        print "f",datetime.datetime.now()
        log.msg("+++++++++++++++++++++++++test1...")
        print "f",datetime.datetime.now()

на выходе в stdout
f 2015-07-09 14:03:37.039811
f 2015-07-09 14:03:37.039876

а в самом логе тишина

если тоже ставить в connectionMade - то все выводит.

И второй вопрос - не догнал зачем FileLogObserver.

заранее спасибо.
apanyovin
ответ на мой вопрос
Your Factory is constructed (its __init__ is called) before logging is initialized; logging starts once all the server components are built and passed to the application service, so that you can print messages to the administrator interactively before the log file consumes stdio. That means that the log.msg calls don't go anywhere. If you log in other methods of Factory such as buildProtocol you will see the log messages in your log file as you expect. In other words this has everything to do with when the code is run (before or after the log file is opened) rather than where the code is declared (what class it's on).
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB