halloween.py mit halloween_log_conf.json
This commit is contained in:
29
logging-config/halloween.py
Normal file
29
logging-config/halloween.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import logging
|
||||||
|
from logging import config
|
||||||
|
import json
|
||||||
|
import random
|
||||||
|
|
||||||
|
class HalloweenFilter(logging.Filter):
|
||||||
|
|
||||||
|
def __init__(self, params=None):
|
||||||
|
self.param = params
|
||||||
|
print('Halloweenfilter initialisiert')
|
||||||
|
|
||||||
|
def filter(self, record:logging.LogRecord)-> bool| logging.LogRecord:
|
||||||
|
|
||||||
|
# Der Unsichtbare soll keine Spuren im Logfile hinterlassen.
|
||||||
|
return record.getMessage().lower().find('unsichtbar') == -1
|
||||||
|
|
||||||
|
visitors = ['Werwolf','Gespenst','Hexe','Unsichtbarer','Vampir','Dämon','Gorilla','Hulk','Mumie']
|
||||||
|
|
||||||
|
treats = ['Bonbons','Twinkies','Lollis','Schokoladen','Kuchen', 'Äpfel']
|
||||||
|
|
||||||
|
secrets = random.SystemRandom()
|
||||||
|
|
||||||
|
with open('halloween_log_conf.json') as file_config:
|
||||||
|
config.dictConfig(json.load(file_config))
|
||||||
|
for v in visitors:
|
||||||
|
logging.info(f'An der Tür klopft eine gruselige Gestalt: {v}')
|
||||||
|
number = secrets._randbelow(20)
|
||||||
|
treat = secrets.choice(treats)
|
||||||
|
logging.info(f'Du gibst ihr {number} {treat} und sie zieht weiter')
|
34
logging-config/halloween_log_conf.json
Normal file
34
logging-config/halloween_log_conf.json
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"version":1,
|
||||||
|
"filters": {
|
||||||
|
"halloween":{
|
||||||
|
"()": "__main__.HalloweenFilter"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"formatters":{
|
||||||
|
"std_out":{
|
||||||
|
"format": "%(asctime)s : %(levelname)s : %(lineno)d : %(message)s",
|
||||||
|
"datefmt":"%I:%M:%S %d.%m.%Y"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"handlers":{
|
||||||
|
"console":{
|
||||||
|
"formatter": "std_out",
|
||||||
|
"class": "logging.StreamHandler",
|
||||||
|
"level": "DEBUG"
|
||||||
|
},
|
||||||
|
"file":{
|
||||||
|
"formatter":"std_out",
|
||||||
|
"class":"logging.FileHandler",
|
||||||
|
"level":"DEBUG",
|
||||||
|
"filename" : "halloween.log",
|
||||||
|
"filters": ["halloween"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root":{
|
||||||
|
"handlers":["console","file"],
|
||||||
|
"level": "DEBUG"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user