File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 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+
128class SQL (object ):
229 """Wrap SQLAlchemy to provide a simple SQL API."""
330
@@ -73,6 +100,7 @@ def _disconnect(self):
73100 self ._connection .close ()
74101 delattr (self , "_connection" )
75102
103+ @_enable_logging
76104 def execute (self , sql , * args , ** kwargs ):
77105 """Execute a SQL statement."""
78106
You can’t perform that action at this time.
0 commit comments