如何在AWS云日志中打印异常堆栈跟踪

时间:2019-05-07 07:14:32

标签: python-3.x exception logging amazon-cloudwatch

我正在使用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

0 个答案:

没有答案