Skip to content

Commit 9540ec3

Browse files
authored
Merge pull request #166 from cs50/logging
using INFO, WARNING, and ERROR instead of DEBUG
2 parents 90fab66 + 42482f9 commit 9540ec3

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
package_dir={"": "src"},
1717
packages=["cs50"],
1818
url="https://github.com/cs50/python-cs50",
19-
version="9.0.0"
19+
version="9.1.0"
2020
)

src/cs50/sql.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -382,24 +382,24 @@ def teardown_appcontext(exception):
382382
elif command in ["DELETE", "UPDATE"]:
383383
ret = result.rowcount
384384

385-
# If constraint violated, return None
385+
# If constraint violated
386386
except sqlalchemy.exc.IntegrityError as e:
387-
self._logger.debug(termcolor.colored(statement, "yellow"))
387+
self._logger.error(termcolor.colored(_statement, "red"))
388388
e = ValueError(e.orig)
389389
e.__cause__ = None
390390
raise e
391391

392392
# If user error
393393
except (sqlalchemy.exc.OperationalError, sqlalchemy.exc.ProgrammingError) as e:
394394
self._disconnect()
395-
self._logger.debug(termcolor.colored(statement, "red"))
395+
self._logger.error(termcolor.colored(_statement, "red"))
396396
e = RuntimeError(e.orig)
397397
e.__cause__ = None
398398
raise e
399399

400400
# Return value
401401
else:
402-
self._logger.debug(termcolor.colored(_statement, "green"))
402+
self._logger.info(termcolor.colored(_statement, "green"))
403403
if self._autocommit: # Don't stay connected unnecessarily
404404
self._disconnect()
405405
return ret

tests/foo.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55

66
import cs50
77

8-
"""
98
db = cs50.SQL("sqlite:///foo.db")
109

1110
logging.getLogger("cs50").disabled = False
11+
logging.getLogger("cs50").setLevel(logging.ERROR)
1212

13-
#db.execute("SELECT ? FROM ? ORDER BY ?", "a", "tbl", "c")
14-
db.execute("CREATE TABLE IF NOT EXISTS bar (firstname STRING)")
13+
db.execute("CREATE TABLE IF NOT EXISTS bar (firstname STRING UNIQUE)")
1514

15+
db.execute("INSERT INTO bar VALUES (?)", "baz")
1616
db.execute("INSERT INTO bar VALUES (?)", "baz")
1717
db.execute("INSERT INTO bar VALUES (?)", "qux")
1818
db.execute("SELECT * FROM bar WHERE firstname IN (?)", ("baz", "qux"))
1919
db.execute("DELETE FROM bar")
20+
2021
"""
2122
2223
db = cs50.SQL("postgresql://postgres@localhost/test")
2324
24-
"""
2525
print(db.execute("DROP TABLE IF EXISTS cs50"))
2626
print(db.execute("CREATE TABLE cs50 (id SERIAL PRIMARY KEY, val VARCHAR(16), bin BYTEA)"))
2727
print(db.execute("INSERT INTO cs50 (val) VALUES('foo')"))
@@ -31,7 +31,6 @@
3131
print(db.execute("CREATE TABLE cs50 (val VARCHAR(16), bin BYTEA)"))
3232
print(db.execute("INSERT INTO cs50 (val) VALUES('foo')"))
3333
print(db.execute("SELECT * FROM cs50"))
34-
"""
3534
3635
print(db.execute("DROP TABLE IF EXISTS cs50"))
3736
print(db.execute("CREATE TABLE cs50 (id SERIAL PRIMARY KEY, val VARCHAR(16), bin BYTEA)"))
@@ -46,3 +45,5 @@
4645
pass
4746
print(db.execute("INSERT INTO cs50 (val) VALUES('qux')"))
4847
#print(db.execute("DELETE FROM cs50"))
48+
49+
"""

0 commit comments

Comments
 (0)