Merge branch 'master' into improved-logging
[EVA-2020-02-2.git] / examples / light.py
index aa895f1131a9fcd96ed1e893460f5907156af449..3442fb489d0ac677636255458a2029a9c5511ad7 100755 (executable)
@@ -2,19 +2,24 @@
 
 import time
 import ltr559
 
 import time
 import ltr559
+import logging
 
 
+logging.basicConfig(
+    format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
+    level=logging.INFO,
+    datefmt='%Y-%m-%d %H:%M:%S')
 
 
-print("""light.py - Print readings from the LTR559 Light & Proximity sensor.
+logging.info("""light.py - Print readings from the LTR559 Light & Proximity sensor.
 
 Press Ctrl+C to exit!
 
 Press Ctrl+C to exit!
-        
+
 """)
 
 try:
     while True:
         lux = ltr559.get_lux()
         prox = ltr559.get_proximity()
 """)
 
 try:
     while True:
         lux = ltr559.get_lux()
         prox = ltr559.get_proximity()
-        print("""Light: {:05.02f} Lux
+        logging.info("""Light: {:05.02f} Lux
 Proximity: {:05.02f}
 """.format(lux, prox))
         time.sleep(1.0)
 Proximity: {:05.02f}
 """.format(lux, prox))
         time.sleep(1.0)