You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
53 lines
1.3 KiB
2 months ago
|
import logging
|
||
|
from logging import config
|
||
|
|
||
|
# Logging Konfiguration definieren.
|
||
|
|
||
|
log_config = {
|
||
|
"version":1,
|
||
|
# root-Logger
|
||
|
"root":{
|
||
|
"handlers" : ["console",'file'],
|
||
|
"level": "DEBUG"
|
||
|
},
|
||
|
"handlers":{
|
||
|
#Handler für Console
|
||
|
"console":{
|
||
|
"formatter": "std_out",
|
||
|
"class": "logging.StreamHandler",
|
||
|
"level": "DEBUG"
|
||
|
},
|
||
|
# Handler für Logdatei
|
||
|
"file":{
|
||
|
"formatter":"std_out",
|
||
|
"class":"logging.FileHandler",
|
||
|
"level":"DEBUG",
|
||
|
"filename":"raspithek.log"
|
||
|
},
|
||
|
},
|
||
|
|
||
|
# Format einer Logzeile
|
||
|
"formatters":{
|
||
|
"std_out": {
|
||
|
"format": "%(asctime)s : %(levelname)s : %(module)s : %(funcName)s : %(lineno)d : (Process Details : (%(process)d, %(processName)s), Thread Details : (%(thread)d, %(threadName)s))\nLog : %(message)s",
|
||
|
"datefmt":"%d-%m-%Y %I:%M:%S"
|
||
|
}
|
||
|
},
|
||
|
}
|
||
|
|
||
|
# Config setzen
|
||
|
config.dictConfig(log_config)
|
||
|
|
||
|
# Logging testen
|
||
|
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()
|
||
|
|