Olympe log filtering (reducing noisy messages)

I’m just posting this because I thought it might be helpful to someone else using Olympe with a physical drone. It’s really hard to read the Olympe logs as currently implemented because they’re filled with messages I don’t care about, but I still want to use DEBUG level logging to find errors.

Continuing the discussion from Change loglevel in Olympe 1.2.1: since the standard Python logging library is now being used, you can use filters to make the output easier to read. Here’s an example. First create a function that returns False when a message is not interesting (because it is spammed to the log).

def is_log_message_interesting(record):
    # filter out noisy logging
    msg = record.getMessage()
    unwanted_messages = ['ardrone3.GPSSettingsState.GeofenceCenterChanged',
     'ardrone3.GPSState.NumberOfSatelliteChanged',
     'common.CommonState.LinkSignalQuality',
     'wifi.rssi_changed',
     'ardrone3.PilotingState.HeadingLockedStateChanged',
     'common.MavlinkState.MavlinkFilePlayingStateChanged',
     'common.FlightPlanState.ComponentStateListChanged',
     'common.FlightPlanState.AvailabilityStateChanged',
     'follow_me.mode_info']
    return not any(m in msg for m in unwanted_messages)

Then connect to a drone and apply the log filter:

drone = olympe.Drone(DRONE_IP)
drone.connect()
drone.logger.addFilter(is_log_message_interesting)

Now your logs will be less noisy. Obviously you can add/remove strings from is_log_message_interesting() to suit your definition of interesting, but I found that the messages listed above print so frequently when connected to a physical drone that it’s impossible to read anything else, like my own print() statements in the python console or Olympe log messages with errors in them.