【发布时间】:2020-04-07 19:32:21
【问题描述】:
我有一个包含很多功能的大型 Python 应用程序。 有时某个函数会向日志报告错误。 我还想添加一个行号,以便找出我的代码中失败的行。
函数示例:
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)
【问题讨论】:
-
this 回答你的问题了吗?
-
您在使用
loggingstdlib 模块吗?目前尚不清楚APP_LOG是哪种记录器。 stdlib 模块在日志记录中提供行号
标签: python python-3.x logging