3

在我的应用程序中,我必须使用 apscheduler。我像这样为 BackgroundScheduler 设置记录器:

self.schedlogger = logging.getLogger("gwserver.{}.sched".format(type(self).__name__))
self.schedlogger.setLevel(logging.WARNING)
self.sched = BackgroundScheduler(logger=self.schedlogger)
self.sched.start()

确实调度程序使用了适当的记录器。但是调度程序内部的执行程序仍然使用默认值。为了克服这个问题,我不得不在上面的代码中添加一行:

self.sched._executors['default']._logger = self.schedlogger

但这对我来说看起来像是一个肮脏的黑客。为调度程序和执行程序设置记录器是否有任何正确的方法?

4

1 回答 1

1

似乎它在 BaseExecutor.start 中是硬编码的:

def start(self, scheduler, alias):
    """
    Called by the scheduler when the scheduler is being started or when the executor is being added to an already
    running scheduler.

    :param apscheduler.schedulers.base.BaseScheduler scheduler: the scheduler that is starting this executor
    :param str|unicode alias: alias of this executor as it was assigned to the scheduler
    """

    self._scheduler = scheduler
    self._lock = scheduler._create_lock()
    self._logger = logging.getLogger('apscheduler.executors.%s' % alias)

请参阅:https ://bitbucket.org/agronholm/apscheduler/src/c534d51a57638e8a8a51c36d4a4128b89f8beb22/apscheduler/executors/base.py?at=master

于 2015-08-12T13:20:44.627 回答