It should be relatively easy, but how do you want to log it?
You can use onUnitOn/onUnitOff or onUnitStateChange to get notified of changes.
Then you can just use timestamps to compare the time between the on/off states and record them somewhere, such as in a hash or just simply log it, depending on your needs.