Olli Graf
2 months ago
6 changed files with 76 additions and 9 deletions
@ -0,0 +1,3 @@ |
|||||
|
example.py |
||||
|
ex2.py |
||||
|
*.log |
@ -0,0 +1,37 @@ |
|||||
|
import logging |
||||
|
from logging import config |
||||
|
import json |
||||
|
|
||||
|
# Filter definieren |
||||
|
class DruckFilter(logging.Filter): |
||||
|
|
||||
|
def __init__(self, params=None): |
||||
|
self.param = params |
||||
|
print('Druckfilter initialisiert') |
||||
|
|
||||
|
def filter(self, record:logging.LogRecord)-> bool| logging.LogRecord: |
||||
|
|
||||
|
# nur Text, der das Wort Druck enthält soll geloggt werden. |
||||
|
return record.getMessage().lower().find('druck') > -1 |
||||
|
|
||||
|
|
||||
|
# Config aus JSON Datei laden und setzen |
||||
|
|
||||
|
with open('log_config.json') as file_config: |
||||
|
config.dictConfig(json.load(file_config)) |
||||
|
|
||||
|
|
||||
|
# Logging testen |
||||
|
def testlogging(): |
||||
|
print('testlogging() aufgerufen.') |
||||
|
logging.debug('Diese Zeile wird ausgefiltert.') |
||||
|
logging.debug('DEBUG/Druckdaten werden gesendet.') |
||||
|
logging.info('INFO/Es werden 2 Seiten gedruckt') |
||||
|
logging.debug('Diese Zeile wird auch ausgefiltert.') |
||||
|
logging.warning('WARN/nicht genügend Papier im Drucker') |
||||
|
logging.error('ERROR/Drucker nicht gefunden.') |
||||
|
logging.critical('CRITICAL/Drucker brennt') |
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
testlogging() |
||||
|
|
@ -0,0 +1,35 @@ |
|||||
|
{ |
||||
|
"version":1, |
||||
|
"filters": { |
||||
|
"drucker":{ |
||||
|
"()": "__main__.DruckFilter", |
||||
|
"params": "noshow" |
||||
|
} |
||||
|
}, |
||||
|
"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" |
||||
|
} |
||||
|
}, |
||||
|
"handlers":{ |
||||
|
"console":{ |
||||
|
"formatter": "std_out", |
||||
|
"class": "logging.StreamHandler", |
||||
|
"level": "DEBUG", |
||||
|
"filters": ["drucker"] |
||||
|
}, |
||||
|
"file":{ |
||||
|
"formatter":"std_out", |
||||
|
"class":"logging.FileHandler", |
||||
|
"level":"DEBUG", |
||||
|
"filename" : "raspithek.log" |
||||
|
} |
||||
|
}, |
||||
|
"root":{ |
||||
|
"handlers":["console","file"], |
||||
|
"level": "DEBUG" |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
@ -1,2 +1,2 @@ |
|||||
./__pycache__ |
__pycache__ |
||||
./network/__pycache__/* |
./network/__pycache__/* |
||||
|
Loading…
Reference in new issue