Python APScheduler how to disable logging

I configured APScheduler to run every second through the cron schedule (kind of necessary / required). Right now I have a registrar sending everything to the console.

If it were not for registration, it was very important for what I'm working on, everything will be fine. But I need registration. What I do not want is an entry in APScheduler. Such things:

  INFO at 2013-05-26 13: 05: 06,007: Job "loadavg.run (trigger: cron [year = '*', month = '*', day = '*', week = '*', day_of_week = ' * ', hour =' * ', minute =' * ', second =' * '], next run at: 2013-05-26 13:05:06) "executed successfully
 INFO at 2013-05-26 13: 05: 06,008: Running job "cpu.run (trigger: cron [year = '*', month = '*', day = '*', week = '*', day_of_week = '*', hour = '*', minute = '*', second = '*'], next run at: 2013-05-26 13:05:07) "(scheduled at 2013-05-26 13:05 : 06) 

I have this in my code after adding cron jobs:

  logging.getLogger ("apscheduler.scheduler"). setLevel (logging.DEBUG) 

No, as far as I know, configuration options for APScheduler to specify protocol information.

I know that I can point the registrar level to ERROR or something like that, but when it is set to INFO, I don't want all this (which seems useless) to be logged as well.

+4
source share
3 answers

At first I assume that you are using APScheduler for cron-like behavior, because if you really ran through cron(8) every second, it

  • Be self-confident because APScheduler claims to be "a much better alternative to running cron scripts externally ..."
  • Maybe something terrible in the system.

According to the fact that the logging module is that it allows your application to have wide control over logging in the library without touching its code, Unfortunately, logging difficult to understand at first.

Since the INFO level indicates that you are not interested, you can:

 class NoRunningFilter(logging.Filter): def filter(self, record): return not record.msg.startswith('Running job') my_filter = NoRunningFilter() logging.getLogger("apscheduler.scheduler").addFilter(my_filter) 

All of them can be specified dynamically using the logging configuration file , but this is a bit more magic than I ever received.

+2
source

You can try this code:

 logging.getLogger('apscheduler.executors.default').propagate = False 
+3
source

Here is my code that works without complaining about missing handlers:

 scheduler = BackgroundScheduler() scheduler.start() scheduler.add_job(every_minute, trigger='cron', second=0, id='every_minute') logging.getLogger('apscheduler.executors.default').setLevel(logging.WARNING) 

It does not completely disable the scheduler logging, but it deletes the informational messages that the OP wanted to get rid of.

0
source

Source: https://habr.com/ru/post/1482860/


All Articles