Disable logging in the schedule library

Purpose: To prevent schedule from being logged every time it starts.

Background:

I am using the logging and schedule libraries in a python project.

My log file contains information about the physical state of the tool launched by the Raspberry Pi, and is updated every 10 seconds.

I am using the schedule library to schedule this periodical log.

Here is the limited documentation I found for schedule .

Problem:

The schedule library registers this statement every time a task runs.

 2016-06-29 09:01:51,022 INFO: Running job every 10 seconds do update_log() (Last run... 

The function that schedule calls update_log() , the function that calculates the variables included in the log, I run every ten seconds and writes them to the log (example below).

 2016-06-29 09:01:51,022 INFO: Dist: 12.3 m Rate: 23.8 cm/s 

Since schedule creates its own (rather useless) log line, it makes a record that I'm really trying to make very difficult to read.

Goal:

Prevent schedule from registering this first statement.

+6
source share
1 answer

The schedule module is used exclusively with the schedule log . You can use the logging library to disconnect this logger from writing to your main log .

 import logging logging.getLogger('schedule').propagate = False 

If you don't need schedule logs at all, you can also disable it by setting your log level above any real log level.

 import logging logging.getLogger('schedule').setLevel(logging.CRITICAL + 10) 

If you just want some messages to go through, set the level to the normal logging level.

Since python2.7, you can also use NullHandler .

 import logging logging.getLogger('schedule').propagate = False logging.getLogger('schedule').addHandler(logging.NullHandler()) 
+6
source

All Articles