logging
This commit is contained in:
4
logging/conf.py
Normal file
4
logging/conf.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import logging
|
||||||
|
__LOGLEVEL__ = logging.DEBUG
|
||||||
|
|
||||||
|
|
5
logging/test.log
Normal file
5
logging/test.log
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
2023-04-29 13:11:26,397 [DEBUG] testlogging: DEBUG/Drucken wir vorbereitet
|
||||||
|
2023-04-29 13:11:26,397 [INFO] testlogging: INFO/Es werden 2 Seiten gedruckt
|
||||||
|
2023-04-29 13:11:26,397 [WARNING] testlogging: WARN/nicht genügend Papier im Drucker
|
||||||
|
2023-04-29 13:11:26,397 [ERROR] testlogging: ERROR/Drucker nicht gefunden.
|
||||||
|
2023-04-29 13:11:26,397 [CRITICAL] testlogging: CRITICAL/Drucker brennt
|
17
logging/testlogging.py
Normal file
17
logging/testlogging.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import logging
|
||||||
|
from conf import __LOGLEVEL__
|
||||||
|
|
||||||
|
logging.basicConfig( format='%(asctime)s [%(levelname)s] %(funcName)s: %(message)s',
|
||||||
|
# filename='test.log',
|
||||||
|
level=__LOGLEVEL__)
|
||||||
|
|
||||||
|
def testlogging():
|
||||||
|
print('testlogging() aufgerufen.')
|
||||||
|
logging.debug('DEBUG/Druckdaten werden gesendet.')
|
||||||
|
logging.info('INFO/Es werden 2 Seiten gedruckt')
|
||||||
|
logging.warning('WARN/nicht genügend Papier im Drucker')
|
||||||
|
logging.error('ERROR/Drucker nicht gefunden.')
|
||||||
|
logging.critical('CRITICAL/Drucker brennt')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
testlogging()
|
@@ -3,21 +3,48 @@
|
|||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
__PIN__ = 18
|
__PIN__ = 23 # GPIO Pin, den wir nutzen
|
||||||
|
__WAIT__ = 0.5 # Warten für 0,5 Sekunden
|
||||||
|
|
||||||
GPIO.setwarnings(False)
|
GPIO.setwarnings(False)
|
||||||
|
|
||||||
|
# benutze Broadcom Pin Nummerierung
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
|
||||||
|
# Pin 23 als Output schalten.
|
||||||
GPIO.setup(__PIN__,GPIO.OUT)
|
GPIO.setup(__PIN__,GPIO.OUT)
|
||||||
|
|
||||||
while True:
|
#Zustand der LED setzen
|
||||||
|
def setLED(state):
|
||||||
|
|
||||||
GPIO.output(__PIN__,GPIO.HIGH)
|
GPIO.output(__PIN__,state)
|
||||||
print('LED ein')
|
|
||||||
|
|
||||||
sleep(0.5)
|
# Dauerschleife, die die LED im Wechsel ein- und ausschaltet.
|
||||||
|
# Wird gestoppt mit CTRL-C
|
||||||
|
def blinkloop():
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
|
||||||
|
# Pin auf HIGH setzen schaltet die LED ein
|
||||||
|
setLED(GPIO.HIGH)
|
||||||
|
print('LED ein')
|
||||||
|
|
||||||
|
sleep(__WAIT__)
|
||||||
|
|
||||||
|
# Pin auf LOW setzen schaltet die LED aus
|
||||||
|
setLED(GPIO.LOW)
|
||||||
|
print('LED aus')
|
||||||
|
sleep(__WAIT__)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
# Zum schluss immer die LED ausschalten.
|
||||||
|
setLED(GPIO.LOW)
|
||||||
|
|
||||||
|
if __name__ =='__main__':
|
||||||
|
blinkloop()
|
||||||
|
GPIO.cleanup(__PIN__)
|
||||||
|
|
||||||
GPIO.output(__PIN__,GPIO.LOW)
|
|
||||||
print('LED aus')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user