Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hShaW-0004pI-2M for psycopg@arkaria.postgresql.org; Mon, 20 May 2019 12:40:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hShaU-0007b2-L5 for psycopg@arkaria.postgresql.org; Mon, 20 May 2019 12:40:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hShaU-0007av-Ae for psycopg@lists.postgresql.org; Mon, 20 May 2019 12:40:18 +0000 Received: from hz1.yz.to ([178.63.61.147]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hShaN-00018C-3q for psycopg@postgresql.org; Mon, 20 May 2019 12:40:17 +0000 Received: from [172.17.6.34] (mail.tbz-pariv.de [146.0.121.193]) by hz1.yz.to (Postfix) with ESMTPSA id 0373A8021585; Mon, 20 May 2019 14:40:07 +0200 (CEST) Subject: Re: Log Stacktrace of current Python Interpreter via PostgreSQL trigger To: Daniele Varrazzo Cc: psycopg@postgresql.org References: <46505a4b-517b-0967-c2f9-1364a794ecef@thomas-guettler.de> From: =?UTF-8?Q?Thomas_G=c3=bcttler?= Message-ID: <2356ac85-773c-7aef-48b6-6f1f0ad4b1d4@thomas-guettler.de> Date: Mon, 20 May 2019 14:43:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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