log file.
Steven D'Aprano
steve at pearwood.info
Tue Jun 14 23:16:47 EDT 2016
On Wed, 15 Jun 2016 05:54 am, Paul Owen wrote:
> logging please.
>
> my pump programme works but I want to log the time etc. when the pump runs
> and stops.
>
> I am trying to improve the programme
>
> I am a novice!
As a novice, start with the simplest thing. Whenever the pump runs or stops,
just call print:
start(pump)
print("Starting")
...
stop(pump)
print("Stopping")
To log to a file instead, change the program to:
import logging
logging.basicConfig(filename='example.log',level=logging.DEBUG)
start(pump)
logging.info("Starting")
...
stop(pump)
logging.info("Stopping")
More information in the logging tutorial:
https://docs.python.org/2/howto/logging.html
https://docs.python.org/3/howto/logging.html
--
Steven
More information about the Python-list
mailing list