title: How to extend `psycopg2.extras.DictCursor`?
body: <p>I want to use a python3-psycopg2 (2.5.4) cursor that can:</p>
  
  <p>1) access query result in a dict-like manner</p>
  
  <p>2) log every sql executed by this cursor with <code>logging</code> module automatically</p>
  
  <p>I tried the following code, it didn't work, what did I do wrong? I can extend <code>psycopg2.extensions.cursor</code>, but that would not allow me to do 1).</p>
  
  <pre><code>class LoggingCursor(psycopg2.extras.DictCursor):
      def __init__(self, *args, **kwargs):  # it didn't work with or
          super().__init__(*args, **kwargs) # without these 2 lines
  
      def execute(self, sql, args=None):
          from beautiful import app
          # logger = blah blah
          logger.debug(self.mogrify(sql, args).decode())
          psycopg2.extensions.cursor.execute(self, sql, args)
  
  cursor = db_conn.cursor(cursor_factory=LoggingCursor)
  </code></pre>
  
  <p>When I <code>cursor.execute(some_sql)</code>, it gives me:</p>
  
  <pre><code>File "some_file.py", line 123, in some_function
    some_var = cursor.fetchone()
  File "/usr/local/lib/python3.4/dist-packages/psycopg2/extras.py", line 63, in fetchone
    res = super(DictCursorBase, self).fetchone()
  File "/usr/local/lib/python3.4/dist-packages/psycopg2/extras.py", line 139, in __init__
    self._index = cursor.index
  
  AttributeError: 'LoggingCursor' object has no attribute 'index'
  </code></pre>