python-3.x - 如何在 aws 云日志中打印异常堆栈跟踪
问题描述
我正在使用 AWS lambda 来执行代码库。
运行 aws lambda 并查看 aws cloudeatch 日志,因此只有最后一个回溯正在打印。
我需要回溯,因为它在本地 python 运行中打印。
class E(Exception):
def __init__(self, *args, **kwargs):
for arg in args:
print(args)
for kw in kwargs:
print(kw)
class A:
def a(self):
try:
x = 1 / 0
except Exception as e:
raise E("error") from e
def handler(event, context):
try:
A().a()
return True
except Exception as e:
raise e
handler(None, None)
输出 :
error
[ERROR] E: error
Traceback (most recent call last):
File "/var/task/lambda-function.py", line 46, in handler
raise e
File "/var/task/lambda-function.py", line 43, in handler
A().a()
File "/var/task/lambda-function.py", line 38, in a
raise E("error") from e
解决方案
推荐阅读
- node.js - 使用 AWS 时,我应该在哪里上传我的应用程序文件?
- excel - Workbook_Open v QueryTable.Refresh BackgroundQuery
- javascript - 将增量 ID 设置为动态创建的元素 (DIV) 并为每个 DIV 分配 onclick 事件
- javascript - 垃圾收集 - 现代 javascript 和 nodejs
- reactjs - 在画布中反应三个纤维锁定对象位置
- bash - 回答多个命令行提示到 GitHub 用户名/密码
- python - 哪个是更好的哈希函数以及为什么: hash((int1, int2, int3)) 或 hash(int1 + int2 + int3)
- google-sheets - 我试图找出一个谷歌表格公式,它将为总金额单元格中的每 12.50 添加 3.13 到一个单元格?
- javascript - 我坚持将代码从旧版本的 Discord Js 转换为现代 Discord Js
- linux - 如何将 \ 与 read 命令一起使用?