Software
- Django 1.9
- Python 3.4
What did I do?
I have the following Django code in my views.py
from django.db import connection
cursor = connection.cursor()
cursor.execute('SELECT p.name, p.name_zh_hans, p.art_number, ....')
rows = cursor.fetchall()
logger = logging.getLogger(__name__)
for row in rows:
row_num += 1
logger.info(row)
for col_num in range(len(row)):
ws.write(row_num, col_num, row[col_num], font_style)
What did I get inside the log file?
(0.005) SELECT p.name, p.name_zh_hans, p.art_number, ....; args=None
(0.005) SELECT p.name, p.name_zh_hans, p.art_number, ....; args=None
(0.006) SELECT p.name, p.name_zh_hans, p.art_number, ....; args=None
What did I expect?
Display of the array contents inside the log file
What went wrong?
You might need to set
logging.basicConfig(level=logging.INFO)
before you calllogging.getLogger(__name__)
.You can check out the Logging Cookbook for a detailed guide.
I belive that what you are seeing are actually logs from django.db.backends, checkout this reference.
You are logging with level log level info meanwhile django.db.backends logs at DEBUG level so checkout also your log handlers to be sure what you are actually logging and what you are not :)
Hope it helps!