I have a large Python app with a lot of functions. Sometimes a certain function reports an error to the log. I want to add a line number also, in order to find out the line in my code that failed.
Example of a function:
def count_user_reminders(userid):
    """ Count amount of user's unmuted reminders in the system """
    reminders_count = -7
    try:
        with pg_get_cursor(POOL) as cursor:
            query = """ SELECT COUNT(*)
                    FROM reminders r, basketdrugs b
                    WHERE r.busketdrugsid = b.id
                    AND r.muted = False
                    AND b.usersid = %s; """
            cursor.execute(query, (userid, ))
            res = cursor.fetchone()
            if res:
                reminders_count = res[0]
    except Exception as err:
        APP_LOG.error(ERROR_TEMPLATE, err)
 
     
    