From c0a7704db8151a802d73de7e08a871dc8b4fede0 Mon Sep 17 00:00:00 2001 From: raspithek Date: Sun, 6 Oct 2024 12:34:46 +0000 Subject: [PATCH] =?UTF-8?q?Dateien=20hochladen=20nach=20=E2=80=9Elogging-c?= =?UTF-8?q?onfig=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit testloggingconfig.py --- logging-config/testloggingconf.py | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 logging-config/testloggingconf.py diff --git a/logging-config/testloggingconf.py b/logging-config/testloggingconf.py new file mode 100644 index 0000000..10c7e9a --- /dev/null +++ b/logging-config/testloggingconf.py @@ -0,0 +1,60 @@ +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" + }, +# Handler für rotierende Logfiles + "rotating": { + "formater":"std_out", + "class": 'logging.handlers.RotatingFileHandler', + "filename": 'logs/random.log', + "maxBytes": 10240 + 'backupCount': 3 + } + }, + +# 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() +