Objective: prevent schedule from logging every time it runs.
Background:
I am using the logging and schedule libraries in a python project.
My log file contains information about the physical state of a instrument run by a Raspberry Pi, and is updated every 10 seconds.
I use the schedule library to schedule that periodic log.
Here is the limited documentation I have found for schedule.
The Problem:
The schedule library logs this statement, every time it runs a job.
2016-06-29 09:01:51,022 INFO: Running job every 10 seconds do update_log() (Last run...
The function that schedule calls is update_log(), a function that calculates the variables included in the log I run every ten seconds and logs them (example below).
2016-06-29 09:01:51,022 INFO: Dist: 12.3 m Rate: 23.8 cm/s
Because schedule is producing its own (fairly useless) log line, it makes the logging I am actually trying to do very difficult to read.
The Goal:
Prevent schedule from logging that first statement.
getLogger(name) is typically executed. The getLogger() function accepts a single argument - the logger's name. It returns a reference to a logger instance with the specified name if provided, or root if not. Multiple calls to getLogger() with the same name will return a reference to the same logger object.
The schedule module is exclusively using the logger called schedule. You can use the logging library to disable this logger from writing to your main logger.
import logging
logging.getLogger('schedule').propagate = False
If you don't want schedule's logs at all, you can also disable it by settings its log level above any real log level.
import logging
logging.getLogger('schedule').setLevel(logging.CRITICAL + 10)
If you just want some messages to get through, set the level to a regular logging level.
Since python2.7, you can also use a NullHandler instead.
import logging
logging.getLogger('schedule').propagate = False
logging.getLogger('schedule').addHandler(logging.NullHandler())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With