-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
49 lines (37 loc) · 1.57 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Initialize Logging
import logging
import util
import sys
from logic_bank.logic_bank import LogicBank
from logic_bank.exec_row_logic import logic_row
from logic_bank.rule_type import constraint
from sqlalchemy.orm import session
from safrs import ValidationError
import db
from logic.rules_bank import declare_logic
""" Initialization
1 - Connect
2 - Register listeners (either hand-coded ones above, or the logic-engine listeners).
"""
util.log("BEGIN - setup logging, connect to db, register listeners")
logic_logger = logging.getLogger('logic_logger') # for debugging user logic
logic_logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(message)s - %(asctime)s - %(name)s - %(levelname)s')
handler.setFormatter(formatter)
logic_logger.addHandler(handler)
do_engine_logging = True
engine_logger = logging.getLogger('engine_logger') # for internals
if do_engine_logging:
engine_logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(message)s - %(asctime)s - %(name)s - %(levelname)s')
handler.setFormatter(formatter)
engine_logger.addHandler(handler)
session: session = db.session
def constraint_handler(message: str, constraint: constraint, logic_row: logic_row): # message: str, constr: constraint, row: logic_row):
raise ValidationError(message)
LogicBank.activate(session=session, activator=declare_logic, constraint_event=constraint_handler )
util.log("LogicBank activated\n")