public inbox for [email protected]  
help / color / mirror / Atom feed
From: Thomas Güttler <[email protected]>
To: Daniele Varrazzo <[email protected]>
Cc: [email protected]
Subject: Re: Log Stacktrace of current Python Interpreter via PostgreSQL trigger
Date: Mon, 20 May 2019 14:43:19 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <CA+mi_8a5rij_5xchPkYPFS3moAtw9i6TrwKndynWfbJ=kFA4fg@mail.gmail.com>
References: <[email protected]>
	<CA+mi_8a5rij_5xchPkYPFS3moAtw9i6TrwKndynWfbJ=kFA4fg@mail.gmail.com>

Am 20.05.19 um 12:19 schrieb Daniele Varrazzo:
> If you use postgres logging in stored procedures you can retrieve the logs in 'connection.notices'.
> 
> http://initd.org/psycopg/docs/connection.html#connection.notices

This sound great. Unfortunately I can't extract the whole stacktrace.
I only get the lines below psycopg, not the above (lines of the callers).

Here is my code:

class MyAppConfig(AppConfig):

     def ready(self):
         connection_created.connect(connection_created_check_for_notice_in_connection)

class ConnectionNoticeList(object):
     def append(self, message):
         if not 'some_magic_of_db_trigger' in message:
             return
         logger.warn('%s %s' % (message, ''.join(traceback.format_stack())))


def connection_created_check_for_notice_in_connection(sender, connection, **kwargs):
     connection.connection.notices=ConnectionNoticeList()


I see this in the logs:

'NOTICE:  some_magic_of_db_trigger: 17909
      File "/snap/pycharm-community/128/helpers/pycharm/_jb_pytest_runner....ork/foo/apps.py", line 47, in append
       logger.warn(\'%s %s\' % (message, \'\'.join(traceback.format_stack())))
   '


traceback.format_stack() inside ConnectionNoticeList.append() extracts not the callers.

Is there a way to get the callers lines?




-- 
Thomas Guettler http://www.thomas-guettler.de/
I am looking for feedback: https://github.com/guettli/programming-guidelines





view thread (4+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Log Stacktrace of current Python Interpreter via PostgreSQL trigger
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox