Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added logging #21

Merged
merged 2 commits into from
May 21, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cs50/sql.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import logging
import re
import sqlalchemy
import sys
@@ -16,6 +17,8 @@ def __init__(self, url, **kwargs):
http://docs.sqlalchemy.org/en/latest/core/engines.html#sqlalchemy.create_engine
http://docs.sqlalchemy.org/en/latest/dialects/index.html
"""
logging.basicConfig(level=logging.DEBUG)
self.logger = logging.getLogger(__name__)
try:
self.engine = sqlalchemy.create_engine(url, **kwargs)
except Exception as e:
@@ -109,6 +112,9 @@ def process(value):
# execute statement
result = self.engine.execute(statement)

# log statement
self.logger.debug(statement)

# if SELECT (or INSERT with RETURNING), return result set as list of dict objects
if re.search(r"^\s*SELECT\s+", statement, re.I):
rows = result.fetchall()