code.py
1 # SPDX-FileCopyrightText: 2019 Dave Astels for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 import time 6 import random 7 from adafruit_pyportal import PyPortal 8 from aio_handler import AIOHandler 9 import adafruit_logging as logging 10 11 device=PyPortal() 12 13 l = logging.getLogger('aio') 14 l.addHandler(AIOHandler('test', device)) 15 16 def go(): 17 while True: 18 t = random.randint(1, 5) 19 if t == 1: 20 print('debug') 21 l.debug("debug message: %d", random.randint(0, 1000)) 22 elif t == 2: 23 print('info') 24 l.info("info message: %d", random.randint(0, 1000)) 25 elif t == 3: 26 print('warning') 27 l.warning("warning message: %d", random.randint(0, 1000)) 28 elif t == 4: 29 print('error') 30 l.error("error message: %d", random.randint(0, 1000)) 31 elif t == 5: 32 print('critical') 33 l.critical("critical message: %d", random.randint(0, 1000)) 34 time.sleep(5.0 + (random.random() * 5.0))