logging does not show the result of array



<ul><li>Django 1.9</li> <li>Python 3.4</li> </ul>

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

<strong>What went wrong?</strong>


You might need to set logging.basicConfig(level=logging.INFO) before you call logging.getLogger(__name__).

You can check out the <a href="https://docs.python.org/3.4/howto/logging-cookbook.html" rel="nofollow">Logging Cookbook</a> for a detailed guide.


I belive that what you are seeing are actually logs from <strong>django.db.backends</strong>, checkout <a href="https://docs.djangoproject.com/en/1.10/topics/logging/#django-db-backends" rel="nofollow">this reference</a>.


Messages relating to the interaction of code with the database. For example, every application-level SQL statement executed by a request is logged at the DEBUG level to this logger.

Messages to this logger have the following extra context:

<strong>duration</strong>: The time taken to execute the SQL statement. <br /><strong>sql</strong>: The SQL statement that was executed. <br /><strong>params</strong>: The parameters that were used in the SQL call. For performance reasons, SQL logging is only enabled when settings.DEBUG is set to True, regardless of the logging level or handlers that are installed.

This logging does not include framework-level initialization (e.g. SET TIMEZONE) or transaction management queries (e.g. BEGIN, COMMIT, and ROLLBACK). Turn on query logging in your database if you wish to view all database queries.


You are logging with level <strong>log level info</strong> meanwhile <strong>django.db.backends</strong> logs at <strong>DEBUG</strong> level so checkout also your log handlers to be sure what you are actually logging and what you are not :)

Hope it helps!


  • Confusing probabilities from scikit-learn randomforest
  • How do I Specify Computed Columns in a Table which are based on another Column in SQL Server?
  • PHP Division Float Value WorkAround
  • How save CGContextRef as .PNG file?
  • Change the colour of pixels in a GdkPixbuf (GTK3)
  • Inverse of matrix and multiplication
  • Add 3D abline to cloud plot in R's lattice package
  • solving two uncoupled ODEs within a loop using python and scipy.integrate.ode
  • Return the SQL Statement of an Explicit Cursor
  • Parsing Data From Long to Wide Format in Python
  • Building Qt project for C++11 standard
  • How to synchronize jQuery dialog box to act like alert() of Javascript
  • DIV instruction jumping to random location?
  • Creating Java object from class name with constructor, which contains parameters [duplicate]
  • how to avoid repetitive constructor in children
  • Excel's Macro-Recorder usage
  • Transactional Create with Validation in ServiceStack Redis Client
  • How to Cache Real-time Data?
  • How to match http request and response using Jersey ContainerRequestFilter and ContainerResponseFilt
  • Is there a way to do normal logging with EureakLog?
  • How to set ini file attributes during an Inno install
  • Setting up SourceTree to merge unity3d scenes with UnityYAMLMerge
  • How to rebase a series of branches?
  • Email format validation in mvc3 view
  • Spring Data JPA custom method causing PropertyReferenceException
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • How to add date and time under each post in guestbook in google app engine
  • Possible to stop flickering java tooltip in heavyweight mode?
  • How to handle AllServersUnavailable Exception
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Upload files with Ajax and Jquery
  • VBA Convert delimiter text file to Excel
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • AngularJs get employee from factory
  • Proper way to use connect-multiparty with express.js?
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • coudnt use logback because of log4j
  • Checking variable from a different class in C#
  • Reading document lines to the user (python)