File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ def _enable_logging (f ):
2
+ """Enable logging of SQL statements when Flask is in use."""
3
+
4
+ import logging
5
+ import functools
6
+
7
+ @functools .wraps (f )
8
+ def decorator (* args , ** kwargs ):
9
+
10
+ # Infer whether Flask is installed
11
+ try :
12
+ import flask
13
+ except ModuleNotFoundError :
14
+ return f (* args , ** kwargs )
15
+
16
+ # Enable logging
17
+ disabled = logging .getLogger ("cs50" ).disabled
18
+ if flask .current_app :
19
+ logging .getLogger ("cs50" ).disabled = False
20
+ try :
21
+ return f (* args , ** kwargs )
22
+ finally :
23
+ logging .getLogger ("cs50" ).disabled = disabled
24
+
25
+ return decorator
26
+
27
+
1
28
class SQL (object ):
2
29
"""Wrap SQLAlchemy to provide a simple SQL API."""
3
30
@@ -73,6 +100,7 @@ def _disconnect(self):
73
100
self ._connection .close ()
74
101
delattr (self , "_connection" )
75
102
103
+ @_enable_logging
76
104
def execute (self , sql , * args , ** kwargs ):
77
105
"""Execute a SQL statement."""
78
106
You can’t perform that action at this time.
0 commit comments