22
22
except (InvalidGitRepository , KeyError ):
23
23
app .config ["GIT_REVISION" ] = "unknown"
24
24
25
+
25
26
db = SQLAlchemy (app )
26
27
migrate = Migrate (app , db )
27
- logger = structlog .get_logger ()
28
28
sentry = Sentry (app )
29
29
30
30
ldap = CSHLDAP (app .config ['LDAP_BIND_DN' ],
@@ -38,8 +38,47 @@ def start_of_year():
38
38
return start
39
39
40
40
# pylint: disable=C0413
41
+ from conditional .models .models import UserLog
42
+
43
+ # Configure Logging
44
+ def request_processor (logger , log_method , event_dict ): # pylint: disable=unused-argument, redefined-outer-name
45
+ if 'request' in event_dict :
46
+ flask_request = event_dict ['request' ]
47
+ event_dict ['user' ] = flask_request .headers .get ("x-webauth-user" )
48
+ event_dict ['ip' ] = flask_request .remote_addr
49
+ event_dict ['method' ] = flask_request .method
50
+ event_dict ['blueprint' ] = flask_request .blueprint
51
+ event_dict ['path' ] = flask_request .full_path
52
+ return event_dict
53
+
54
+
55
+ def database_processor (logger , log_method , event_dict ): # pylint: disable=unused-argument, redefined-outer-name
56
+ if 'request' in event_dict :
57
+ if event_dict ['method' ] != 'GET' :
58
+ log = UserLog (
59
+ ipaddr = event_dict ['ip' ],
60
+ user = event_dict ['user' ],
61
+ method = event_dict ['method' ],
62
+ blueprint = event_dict ['blueprint' ],
63
+ path = event_dict ['path' ],
64
+ description = event_dict ['event' ]
65
+ )
66
+ db .session .add (log )
67
+ db .session .flush ()
68
+ db .session .commit ()
69
+ del event_dict ['request' ]
70
+ return event_dict
71
+
72
+ structlog .configure (processors = [
73
+ request_processor ,
74
+ database_processor ,
75
+ structlog .processors .KeyValueRenderer ()
76
+ ])
77
+
78
+ logger = structlog .get_logger ()
79
+
41
80
42
- from conditional .blueprints .dashboard import dashboard_bp
81
+ from conditional .blueprints .dashboard import dashboard_bp # pylint: disable=ungrouped-imports
43
82
from conditional .blueprints .attendance import attendance_bp
44
83
from conditional .blueprints .major_project_submission import major_project_bp
45
84
from conditional .blueprints .intro_evals import intro_evals_bp
0 commit comments