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.
42 lines
1.3 KiB
42 lines
1.3 KiB
1 month ago
|
#encoding: utf-8
|
||
2 months ago
|
import logging
|
||
|
from logging import config
|
||
|
import json
|
||
|
import random
|
||
1 month ago
|
import JSONFormatter
|
||
|
|
||
|
#JSON Formatter
|
||
|
ATTR_TO_JSON = ['created', 'filename', 'funcName', 'levelname', 'lineno', 'module', 'msecs', 'msg', 'name', 'pathname', 'process', 'processName', 'relativeCreated', 'thread', 'threadName']
|
||
|
class JsonFormatter:
|
||
|
def format(self, record):
|
||
|
obj = {attr: getattr(record, attr)
|
||
|
for attr in ATTR_TO_JSON}
|
||
|
return json.dumps(obj, indent=4)
|
||
|
|
||
|
#CustomFilter
|
||
2 months ago
|
|
||
|
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
|
||
|
|
||
1 month ago
|
visitors = ['Werwolf','Gespenst','Hexe','Unsichtbarer','Vampir','Dämon','Gorilla','Monster','Mumie']
|
||
2 months ago
|
|
||
|
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')
|